/// <summary> /// Disposing /// </summary> public void Dispose() { //this.SharmIPC.LogException("dispose test", new Exception("p7")); try { if (mt != null) { mt.ReleaseMutex(); mt.Close(); mt.Dispose(); mt = null; } } catch { } //this.SharmIPC.LogException("dispose test", new Exception("p6")); if (rwh != null) { rwh.Dispose(); rwh = null; } //this.SharmIPC.LogException("dispose test", new Exception("p7")); }
/// <summary> /// /// </summary> /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param> /// <param name="SharmIPC">SharmIPC instance</param> /// <param name="bufferCapacity"></param> /// <param name="maxQueueSizeInBytes"></param> /// <param name="protocolVersion"></param> public SharedMemory(string uniqueHandlerName, SharmIpc SharmIPC, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, tiesky.com.SharmIpc.eProtocolVersion protocolVersion = tiesky.com.SharmIpc.eProtocolVersion.V1) { this.SharmIPC = SharmIPC; this.maxQueueSizeInBytes = maxQueueSizeInBytes; this.ProtocolVersion = protocolVersion; //if (dataArrived == null) // throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty"); if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200) { throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols"); } if (bufferCapacity < 256) { bufferCapacity = 256; } if (bufferCapacity > 1000000) //max 1MB { bufferCapacity = 1000000; } this.uniqueHandlerName = uniqueHandlerName; this.bufferCapacity = bufferCapacity; try { mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex"); if (mt.WaitOne(500)) { instanceType = eInstanceType.Master; } else { instanceType = eInstanceType.Slave; if (mt != null) { //mt.ReleaseMutex(); mt.Close(); mt.Dispose(); mt = null; } } } catch (System.Threading.AbandonedMutexException) { instanceType = eInstanceType.Master; } Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName); rwh = new ReaderWriterHandler(this); }
/// <summary> /// Disposing /// </summary> public void Dispose() { try { if (mt != null) { mt.ReleaseMutex(); mt.Close(); mt.Dispose(); mt = null; } } catch { } if (rwh != null) { rwh.Dispose(); rwh = null; } }
/// <summary> /// /// </summary> /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param> /// <param name="bufferCapacity"></param> /// <param name="dataArrived">MsgId of the sender, payload</param> public SharedMemory(string uniqueHandlerName, Action<eMsgType, ulong, byte[]> dataArrived, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000) { if (dataArrived == null) throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty"); if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200) throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols"); if (bufferCapacity < 256) bufferCapacity = 256; if (bufferCapacity > 1000000) //max 1MB bufferCapacity = 1000000; this.uniqueHandlerName = uniqueHandlerName; this.bufferCapacity = bufferCapacity; try { mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex"); if (mt.WaitOne(500)) { instanceType = eInstanceType.Master; } else { instanceType = eInstanceType.Slave; if (mt != null) { //mt.ReleaseMutex(); mt.Close(); mt.Dispose(); mt = null; } } } catch (System.Threading.AbandonedMutexException) { instanceType = eInstanceType.Master; } Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName); rwh = new ReaderWriterHandler(this, dataArrived); }
/// <summary> /// Disposing /// </summary> public void Dispose() { try { if (mt != null) { mt.ReleaseMutex(); mt.Close(); mt.Dispose(); mt = null; } } catch{ } if (rwh != null) { rwh.Dispose(); rwh = null; } }