Beispiel #1
0
        /// <summary>
        /// Stops receiving of the data.
        /// </summary>
        public void Close()
        {
            if (threadProcessing != null)
            {
                isRunning = false;
                eventDataReady.Set();

                // wait for thread to finish:
                if (threadProcessing != null)
                {
                    threadProcessing.Join(3000);
                }

                threadProcessing = null;
            }

            if (eventBufferReady != null)
            {
                eventBufferReady.Close();
                eventBufferReady = null;
            }

            if (eventDataReady != null)
            {
                eventDataReady.Close();
                eventDataReady = null;
            }

            if (sharedMemory != null)
            {
                sharedMemory.Close();
                sharedMemory = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reinitialize and start processing of messages.
        /// </summary>
        public void Start()
        {
            Close();
            eventBufferReady = SysEventHelper.CreateOrOpen(BufferReadyName, EventResetMode.AutoReset, false);
            eventDataReady   = SysEventHelper.CreateOrOpen(DataReadyName, EventResetMode.AutoReset, false);
            sharedMemory     = new DebugSharedMemory(SharedMemoryName);

            // check if opening handles failed:
            if (eventBufferReady == null || eventDataReady == null || sharedMemory.Address == IntPtr.Zero)
            {
                Close();
                return;
            }

            // create processing units:
            if (threadProcessing == null)
            {
                // main thread listening for messages:
                threadProcessing = new Thread(ThreadMonitor);
                threadProcessing.IsBackground = true;
                threadProcessing.Start();
            }
        }