- Joined
- Oct 5, 2008
- Messages
- 36
- Reaction score
- 5
How do I check for processes in C# and then write to label1 if it is running or not.
Thanks, in advance.
Thanks, in advance.
How do I check for processes in C# and then write to label1 if it is running or not.
Thanks, in advance.
class Program
{
static void Main(string[] args)
{
new Thread(new ThreadStart(CheckProcess)).Start();
}
static void CheckProcess()
{
while (true)
{
// Code for check starts here. I recoment use if.
}
using System.Diagnostics;
Process.GetProcesses() method, as seen in this example:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
p.StartTime (Shows the time the process started)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken)
p.Threads ( gives access to the collection of threads in the process)
public void FindProcess()
{
foreach (Process checkforprocess in Process.GetProcesses())
{
if (checkforprocess.ProcessName.Equals("explorer.exe"))
{
label1.Text = "Running";
}
else
{
label1.Text = "Not Running";
}
}
}