3
Answers

Check running processes on a mobile device programmatically

Photo of Nora

Nora

15y
9.4k
1
Hi,
i have a windows mobile application written in c#, i want to add a code to this application so when it is installed on my mobile and before it starts it needs to check if there is already an instance of this application running , if so it terminates it .. plz can u help me to write a code to check all running processes then find my applicaton in windows mobile application ??!!

Answers (3)

0
Photo of Monu Dhanda
NA 13 1 8y
hi kiran i need your this code can you help me
0
Photo of Nora
NA 4 0 15y

i'm trying to use your code but i'm getting an error in below line that says 'System.Threading.Mutex' does not contain a constructor that takes '3' arguments
 Mutex m = new Mutex(true, MutexName, out WasCreated);
do u have any idea why i'm i getting this error.
Thank you,
0
Photo of Sam Hobbs
55 29.4k 2.1m 15y
If you only need to detect a previous instance, then a Mutex is easy and effective. I am not sure you can do this with Windows Mobile, but probably you can. Note that you should place this code in the Program.cs file, not in the Form class. Put this code just before the line that says "Application.Run(new Form1());" or something such as that.
bool WasCreated;
const string MutexName = "Project_76468";
Mutex m = new Mutex(true, MutexName, out WasCreated);
if (!WasCreated)
{
// MessageBox.Show("A previous instance exists");
return;
}

Also, after the "Application.Run(new Form1());" you need to also do the following :
GC.KeepAlive(m);

That line is not important for small programs, but always use it anyway when using the above code that uses the Mutex.