Gold
Gold

Reputation: 62544

How to prevent my program to open more than one time (Windows mobile)

How to prevent my program to open more than one time (Windows mobile) ?

and how I can make reset to my program (Windows mobile) ?

thank's

Upvotes: 0

Views: 902

Answers (3)

mjf
mjf

Reputation: 357

If you have a .Net CF framework appplication, this how to video walks you through, step by test how to do this. link text

Thanks, Mike

Upvotes: 1

Franklin Munoz
Franklin Munoz

Reputation: 917

First, to check if your program is already running, create a named object on WinMain (ie. a named Mutex), if the create succeeds, then there are no other instances of your program running, if it fails because it exists, then you know that there is another instance of your program running. In that case use FindWindow (http://msdn.microsoft.com/en-us/library/aa929233.aspx) to search for the window of your application and then just bring it to the foreground via SetForegroundWindow (http://msdn.microsoft.com/en-us/library/aa923858.aspx)

hope this helps...

Upvotes: 1

Mike Dinescu
Mike Dinescu

Reputation: 55750

To prevent running multiple instances of you program you could use a named Mutex.

See this question. The same should apply to Windows Mobile.

I'm not sure what you mean by make reset to your program, but if you mean rebooting the device - you may want to take a look at the KernelIoControl function. Here's more information about how to p/invoke KernelIoControl.

[DllImport("coredll.dll")]
public static extern int KernelIoControl(int dwIoControlCode, 
                                         IntPtr lpInBuf, 
                                         int nInBufSize, 
                                         IntPtr lpOutBuf, 
                                         int nOutBufSize, 
                                         ref int lpBytesReturned);

//.. and the invocation..
int retBytes = 0;
// Reboot device
KernelIoControl(((0x101 << 16) | (15 << 2)), IntPtr.Zero, 0, IntPtr.Zero, 0, ref retBytes);

Upvotes: 0

Related Questions