How to run an external application through a C# application?
https://www.tutorialspoint.com/how-to-run-an-external-application-through-a-chash-application
-
29-09-2020 - |
Question
How to run an external application through a C# application?
An external application can be run from a C# application using Process. A process is a program that is running on your computer. This can be anything from a small background task, such as a spell-checker or system events handler to a full-blown application like Notepad etc.
Each process provides the resources needed to execute a program. Each process is started with a single thread, known as the primary thread. A process can have multiple threads in addition to the primary thread. Processes are heavily dependent on system resources available while threads require minimal amounts of resource, so a process is considered as heavyweight while a thread is termed as a lightweight process. Process is present in System.Diagnostics namespace.
Example to run 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(); } } }
The above output shows the console application opened Notepad with the name DemoText provided in the arguments.
Example to run 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.