2
Answers

Getting Process ID of a my running process

Photo of Nora

Nora

15y
12.5k
1
I have windows mobile application, i want to get by C# code its Process ID (PID) while its running .. so any one know function that return PID ?

Answers (2)

0
Photo of dominic scanlan
NA 2 0 15y

Process
p = Process.GetCurrentProcess();
int i = p.Id;
0
Photo of Lalit M
NA 6.7k 48k 15y
use this code sample to get PID

using System.Diagnostics;
private void GetProcessStatus()
{
try
{
//If you know the name of the process
Process[] myProcesses = Process.GetProcessesByName("mspaint");
//If you know the PID of the process use the commented line below
//Process[] myProcesses = Process.GetProcessById("2341");
//Check to see if the process array length is greater than 0
if(myProcesses.Length > 0)
{
MessageBox.Show("The Process Microsoft Paint(mspaint) is currently running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The Process Microsoft Paint(mspaint) is currently NOT running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch(Exception ex)
{
MessageBox.Show("An Exception Occoured: " + ex.Message, "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}


check also