private void Blinding() { if (_mutex.WaitOne(new TimeSpan(100))) { try { using (MemoryMappedViewStream streamReader = _mmf.CreateViewStream(MMF_RECEIVE_OFFSET, MMF_RECEIVE_SIZE)) { using (BinaryReader reader = new BinaryReader(streamReader)) { int len = reader.ReadInt32(); if (len > 0) { if (len != (MMF_RECEIVE_SIZE - sizeof(int))) { throw new Exception("接收結構大小與MMF分配容量不符"); } this.ClientBlock = (MMFClientBlock)MarshalEx.BytesToStuct(reader.ReadBytes(len), typeof(MMFClientBlock)); } } } using (MemoryMappedViewStream streamWriter = _mmf.CreateViewStream(MMF_SEND_OFFSET, MMF_SEND_SIZE)) { using (BinaryWriter writer = new BinaryWriter(streamWriter)) { byte[] data = MarshalEx.StructToBytes(this.ServerBlock); if (data.Length > (MMF_SEND_SIZE - sizeof(int))) { throw new Exception("傳送結構大小大於MMF分配容量"); } writer.Write(data.Length); writer.Write(data); } } } catch (Exception ex) { OnErrorRaised(ex); } finally { _mutex.ReleaseMutex(); } } }