public void CanReadWriteSerialize() { using (var mmf = MemoryMappedFile.CreateNew("test_mmf", ChannelConfiguration.Instance.ChannelSize)) { using (var view = new MemoryMappedFileView(mmf.CreateViewStream(0, ChannelConfiguration.Instance.ChannelSize, MemoryMappedFileAccess.ReadWrite))) { const string TextToWrite = "text to serialize"; view.WriteSerialize(TextToWrite); var readedObject = view.ReadDeserialize(); readedObject.Should().Be(TextToWrite); } } }
/// <summary> /// Initializes a new instance of the <see cref="ProcessMailBox"/> class. /// </summary> /// <param name="name"> /// The name for the semaphores and the shared memory file. /// </param> public ProcessMailBox(string name, TimeSpan sendReceiveTimeout) { this.sendReceiveTimeout = sendReceiveTimeout; this.ChannelName = name; this.mailBoxSync = new SendReceiveLock(name + ".FullMutex.MailBox", name + ".EmptyMutex.MailBox"); this.file = MemoryMappedFile.CreateOrOpen( name + ".MemoryMappedFile.MailBox", ChannelConfiguration.Instance.ChannelSize, MemoryMappedFileAccess.ReadWrite); this.view = new MemoryMappedFileView( this.file.CreateViewStream( 0, ChannelConfiguration.Instance.ChannelSize, MemoryMappedFileAccess.ReadWrite)); }
private void Dispose(bool disposing) { if (this.disposed) { return; } if (disposing) { this.view.Dispose(); this.file.Dispose(); Task.Factory.StartNew(() => this.mailBoxSync.Dispose()); } this.view = null; this.file = null; this.mailBoxSync = null; this.disposed = true; }