/// <summary> /// Sets the window handle of the application /// </summary> public bool SetWindowHandle(IntPtr handle) { if (m_Disposed) { throw new ObjectDisposedException("ApplicationInstance"); } m_Info.WindowHandle = handle; if (m_Memory != null) { m_Memory.Lock(); try { m_Memory.AddObject(m_Info, true); return(true); } catch (SharedMemoryException) { return(false); } finally { m_Memory.Unlock(); } } else { try { m_Memory = new SharedMemory(m_Appname, m_Info); return(true); } catch (SharedMemoryException) { return(false); } } }
/// <summary> /// Tries to get information about the other process /// </summary> private static ApplicationInfo GetApplicationInfo(String appName) { try { using (SharedMemory mem = new SharedMemory(appName)) { mem.Lock(); try { ApplicationInfo info = (ApplicationInfo)mem.GetObject(); return(info); } finally { mem.Unlock(); } } } catch (SharedMemoryException) { return(null); } }