static IntPtr getHandle(string key) { using (System.IO.MemoryMappedFiles.MemoryMappedFile mmf = System.IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(key)) { using (System.IO.MemoryMappedFiles.MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor()) { IntPtr handler = IntPtr.Zero; accessor.Read(0, out handler); return(handler); } } }
private void WriteHandle(string key, IntPtr handler) { System.IO.MemoryMappedFiles.MemoryMappedFile mmf = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(key, 1024000); using (System.IO.MemoryMappedFiles.MemoryMappedViewStream stream = mmf.CreateViewStream()) { using (System.IO.MemoryMappedFiles.MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor()) { accessor.Write(0, ref handler); } } }
public MMFinterComT(string ctrIpcChannelNameStr, string ctrIpcThreadName, int ctrMMFSize) { this.DipositChlName = ctrIpcChannelNameStr; this.DipositSize = ctrMMFSize; this.DipositThrdName = ctrIpcThreadName; mmf = MemoryMappedFile.CreateOrOpen(DipositChlName, DipositSize); accessor = mmf.CreateViewAccessor(0, DipositSize, System.IO.MemoryMappedFiles.MemoryMappedFileAccess.ReadWrite); //if (started) //smLock = new System.Threading.Mutex(true, IpcMutxName, out locked); ReadPosition = -1; writePosition = -1; this.dataToSend = new List <byte[]>(); this.statusSet = new List <string>(); }
public virtual void Close() { if (accessor != null) { try { accessor.Dispose(); accessor = null; } catch { } } if (this.mmf != null) { try { mmf.Dispose(); mmf = null; } catch { } } disposed = true; GC.SuppressFinalize(this); }