Esempio n. 1
0
        static void Main(string[] args)
        {
            MemoryMappedFileCommunicator communicator = new MemoryMappedFileCommunicator("MemoryMappedShare", 4096);

            // This process reads data that begins in the position 2000 and writes starting from the position 0.
            communicator.ReadPosition  = 2000;
            communicator.WritePosition = 0;

            // Creates an handler for the event that is raised when data are available in the
            // MemoryMappedFile.
            communicator.DataReceived += new EventHandler <MemoryMappedDataReceivedEventArgs>(communicator_DataReceived);
            communicator.StartReader();

            bool quit = false;

            Console.WriteLine("Write messages and press ENTER to send (empty to terminate): ");
            while (!quit)
            {
                string message = Console.ReadLine();
                if (!string.IsNullOrEmpty(message))
                {
                    var data = System.Text.Encoding.UTF8.GetBytes(message);
                    communicator.Write(data);
                }
                else
                {
                    quit = true;
                }
            }

            communicator.Dispose();
            communicator = null;
        }
Esempio n. 2
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     // Closes the reader thread.
     communicator.CloseReader();
     communicator.Dispose();
     communicator = null;
 }
Esempio n. 3
0
 public void Dispose()
 {
     _handlers.Clear();
     _com.Dispose();
 }