How to create a single instance application on Win CE?
-----------------------------------------------------------
this example run a single instance of application on WinCE operation systems (devices).
On WindowMobile 6 (Pocket PC) operation systems,
by default, only one instance of the app will run!
here a sample code for Unique application running (starting):
static class Program
{
///
/// The main entry point for the application.
///
[MTAThread]
static void Main()
{
IntPtr eventHandle = IntPtr.Zero;
try
{
String appName = "UniqueAppName_Event";
eventHandle = CreateEvent(IntPtr.Zero, true, false, appName );
bool isFirstInstance = Marshal.GetLastWin32Error() == 0;
if (isFirstInstance == true)
{
Application.Run(new Form1());
}
}
finally
{
if (eventHandle != IntPtr.Zero)
{
CloseHandle(eventHandle);
}
}
}
#region Imports
[DllImport("Coredll.dll", SetLastError = true)]
static extern IntPtr CreateEvent(IntPtr alwaysZero, bool manualReset, bool initialState, string name);
[DllImport("Coredll.dll", SetLastError = true)]
static extern int CloseHandle(IntPtr handle);
#endregion
}
this ensure a single instance of Windows Form application...