protected virtual void Dispose(bool disposing) { #if !MONO if (disposing) { if (m_PipeStream != null) { if (m_AsyncResult != null) { /* * try * { * m_PipeStream.EndWaitForConnection(m_AsyncResult); * } * catch (Exception) * { * } */ m_AsyncResult = null; } m_PipeStream.Dispose(); m_PipeStream = null; } if (m_Memory != null) { m_Memory.Lock(); m_Memory.Unlock(); m_Memory.Dispose(); m_Memory = null; } } #endif m_Disposed = true; }
private ApplicationInstance(String appName) { m_Info = new ApplicationInfo(IntPtr.Zero, String.Empty); m_Appname = appName; #if !MONO m_Memory = new SharedMemory(appName, m_Info); CreatePipe(); #endif }
/// <summary> /// Initialisiert einen neue Instanz der /// <see cref="T:IpcTests.IO.Ipc.SharedMemory"/>-Klasse. /// </summary> /// <param name="name">Der Name des SharedMemory Segment.</param> /// <param name="obj">Das Objekt welches im SharedMemory Segment gespeichert werden soll.</param> /// <remarks> /// Dieser Konstruktor kann benutzt werden um beim instanzieren der Klasse gleich /// Daten in das ShredMemory Segment zu schreiben. Die Grösse des SharedMemory Segment /// wird automatisch ermittelt. /// </remarks> public SharedMemory(string name, object obj) : this(name, SharedMemoryProcedure.Create, SharedMemory.GetOptMemorySize(obj)) { // das übergebene Objekt in das SharedMemory Segment schreiben Lock(); try { this.AddObject(obj, false); } finally { Unlock(); } }
/// <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); } }
/// <summary> /// Sets the currently loaded project /// </summary> public bool SetLoadedProject(String project) { if (m_Disposed) { throw new ObjectDisposedException("ApplicationInstance"); } m_Info.LoadedProject = project; 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> /// 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); } } }