Home  >  Article  >  Backend Development  >  How to run external application through C# application?

How to run external application through C# application?

王林
王林forward
2023-09-09 15:05:011416browse

You can run external applications from a C# application using Process. A process is a program that runs on your computer. This can be anything from a small background task (such as a spell checker or a system event handler) to a full-blown application (such as Notepad, etc.).

Each process provides the resources needed to execute the program. Every process is started by a thread, called the main thread. A process can have multiple threads in addition to the main thread. Processes heavily depend on the available system resources, while threads require minimal resources, so processes are considered heavyweight processes, while threads are called lightweight processes. The process exists in the System.Diagnostics namespace.

Example of running Notepad from C# application

using System;
using System.Diagnostics;
namespace DemoApplication{
   class Program{
      static void Main(){
         Process notepad = new Process();
         notepad.StartInfo.FileName = "notepad.exe";
         notepad.StartInfo.Arguments = "DemoText";
         notepad.Start();
         Console.ReadLine();
      }
   }
}

How to run external application through C# application?

The above output shows that the console application opens Notepad which The name is the DemoText provided in the parameter.

Example of running browser from C# application

using System;
using System.Diagnostics;
namespace DemoApplication{
   class Program{
      static void Main(){
         Process.Start("https://www.google.com/");
         Console.ReadLine();
      }
   }
}

The above code will open the browser and redirect to www.google.com.

The above is the detailed content of How to run external application through C# application?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete