示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param>
        /// <param name="SharmIPC">SharmIPC instance</param>
        /// <param name="bufferCapacity"></param>
        /// <param name="maxQueueSizeInBytes"></param>
        /// <param name="protocolVersion"></param>
        public SharedMemory(string uniqueHandlerName, SharmIpc SharmIPC, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000, tiesky.com.SharmIpc.eProtocolVersion protocolVersion = tiesky.com.SharmIpc.eProtocolVersion.V1)
        {
            this.SharmIPC            = SharmIPC;
            this.maxQueueSizeInBytes = maxQueueSizeInBytes;
            this.ProtocolVersion     = protocolVersion;


            //if (dataArrived == null)
            //    throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty");

            if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200)
            {
                throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols");
            }

            if (bufferCapacity < 256)
            {
                bufferCapacity = 256;
            }

            if (bufferCapacity > 1000000)    //max 1MB
            {
                bufferCapacity = 1000000;
            }

            this.uniqueHandlerName = uniqueHandlerName;
            this.bufferCapacity    = bufferCapacity;

            try
            {
                mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex");

                if (mt.WaitOne(500))
                {
                    instanceType = eInstanceType.Master;
                }
                else
                {
                    instanceType = eInstanceType.Slave;
                    if (mt != null)
                    {
                        //mt.ReleaseMutex();
                        mt.Close();
                        mt.Dispose();
                        mt = null;
                    }
                }
            }
            catch (System.Threading.AbandonedMutexException)
            {
                instanceType = eInstanceType.Master;
            }

            Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);

            rwh = new ReaderWriterHandler(this);
        }
示例#2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uniqueHandlerName">Can be name of APP, both syncronized processes must use the same name and it must be unique among the OS</param>
        /// /// <param name="SharmIPC">SharmIPC instance</param>
        /// <param name="bufferCapacity"></param>        
        public SharedMemory(string uniqueHandlerName, SharmIpc SharmIPC, long bufferCapacity = 50000, int maxQueueSizeInBytes = 20000000)
        {
            this.SharmIPC = SharmIPC;

            //if (dataArrived == null)
            //    throw new Exception("tiesky.com.SharmIpc: dataArrived callback can't be empty");

            if (String.IsNullOrEmpty(uniqueHandlerName) || uniqueHandlerName.Length > 200)
                throw new Exception("tiesky.com.SharmIpc: uniqueHandlerName can't be empty or more then 200 symbols");

            if (bufferCapacity < 256)
                bufferCapacity = 256;

            if (bufferCapacity > 1000000)    //max 1MB
                bufferCapacity = 1000000;

            this.uniqueHandlerName = uniqueHandlerName;
            this.bufferCapacity = bufferCapacity;

            try
            {
                mt = new Mutex(true, uniqueHandlerName + "SharmNet_MasterMutex");

                if (mt.WaitOne(500))
                {
                    instanceType = eInstanceType.Master;
                }
                else
                {
                    instanceType = eInstanceType.Slave;
                    if (mt != null)
                    {
                        //mt.ReleaseMutex();
                       // mt.Close();
                        mt.Dispose();
                        mt = null;
                    }
                }
            }
            catch (System.Threading.AbandonedMutexException)
            {
                instanceType = eInstanceType.Master;
            }

            #if WINDOWS_UWP
            System.Diagnostics.Debug.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);
            #else
            Console.WriteLine("tiesky.com.SharmIpc: " + instanceType + " of " + uniqueHandlerName);
            #endif

            rwh = new ReaderWriterHandler(this);
        }