예제 #1
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();
        }
예제 #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();
            }
        }