// constructor public SingleInstanceManager(Window instance, ShowApplicationCallback callback) { m_Instance = instance; m_callback = callback; //try to our event m_EventHandle = OpenEvent(EVENT_MODIFY_STATE | SYNCHRONIZE, false, EVENT_NAME); if (m_EventHandle == IntPtr.Zero) //if it doesn't exist { //create our event m_EventHandle = CreateEvent(IntPtr.Zero, true, false, EVENT_NAME); if (m_EventHandle != IntPtr.Zero) //if successfull { Thread thread = new Thread(new ThreadStart(WaitForSignal)) { Name = "Single instance manager" }; thread.Start(); } } else { SetEvent(m_EventHandle); MessageBox.Show("There is already an instance of Witty"); Environment.Exit(0); } }
/// <summary> /// /// </summary> /// <param name="instance"></param> /// <param name="callback"></param> public SingleInstanceManager(Form instance, ShowApplicationCallback callback) : this() { setObject(instance, callback); }
/// <summary> /// /// </summary> /// <param name="instance"></param> /// <param name="callback"></param> public void setObject(Form instance, ShowApplicationCallback callback) { m_Instance = instance; m_callback = callback; }