Ejemplo n.º 1
0
 /// <summary>
 /// Instanciate a new Interprocess Mailbox.
 /// </summary>
 /// <param name="name">The name for the Win32 semaphores and the shared memory file.</param>
 /// <param name="size">The size of the shared memory in terms of bytes.</param>
 public ProcessMailBox(string name, int size)
 {
     empty = new ProcessSemaphore(name + ".EmptySemaphore.MailBox", 1, 1);
     full  = new ProcessSemaphore(name + ".FullSemaphore.MailBox", 0, 1);
     file  = MemoryMappedFile.CreateFile(name + ".MemoryMappedFile.MailBox", MemoryMappedFile.FileAccess.ReadWrite, size);
     view  = file.CreateView(0, size, MemoryMappedFileView.ViewAccess.ReadWrite);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Instanciates an Inter-Process message channel.
        /// </summary>
        /// <param name="size">The count of messages the channel can queue before it blocks.</param>
        /// <param name="name">The channel's name. Must be the same for all instances using this channel.</param>
        /// <param name="maxBytesPerEntry">The maximum serialized message size in terms of bytes. Must be the same for all instances using this channel.</param>
        public ProcessChannel(int size, string name, int maxBytesPerEntry)
        {
            int fileSize = 64 + size * maxBytesPerEntry;

            empty = new ProcessSemaphore(name + ".EmptySemaphore.Channel", size, size);
            full  = new ProcessSemaphore(name + ".FullSemaphore.Channel", 0, size);
            mutex = new ProcessSemaphore(name + ".MutexSemaphore.Channel", 1, 1);
            file  = MemoryMappedFile.CreateFile(name + ".MemoryMappedFile.Channel", MemoryMappedFile.FileAccess.ReadWrite, fileSize);
            view  = file.CreateView(0, fileSize, MemoryMappedFileView.ViewAccess.ReadWrite);
            queue = new MemoryMappedQueue(view, size, maxBytesPerEntry, true, 0);
            if (queue.Length < size || queue.BytesPerEntry < maxBytesPerEntry)
            {
                throw new MemoryMappedArrayFailedException();
            }
        }