示例#1
0
 public void Initialize()
 {
     lock (_requests)
         _requests = new List <string>();
     _socket?.Dispose();
     _socket = null;
     _context?.Dispose();
     _context       = null;
     _workerThreads = new List <WorkerThread>();
 }
示例#2
0
 internal void Stop()
 {
     if (context != null)
     {
         context.Dispose();
     }
 }
示例#3
0
        internal void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                // if this is a dispose call dispose on all state you
                // hold, and take yourself off the Finalization queue.
                if (disposing)
                {
                    /*
                     * foreach (var cTasks in m_ConstituentTasks)
                     * {
                     *  if (cTasks != null)
                     *      cTasks.Dispose();
                     * }*/

                    //if(m_Cts != null)
                    //    m_Cts.Cancel();
                    if (m_ctx != null)
                    {
                        m_ctx.Dispose();
                    }
                    m_Cts.Dispose();
                }

                // perform any custom clean-up operations
                // such as flushing the stream
                // free your own state (unmanaged objects)
                AdditionalCleanup();

                this.disposed = true;
            }

            //base.Dispose(disposing);
        }
示例#4
0
        public void ConnectToGW(string args)//
        {
            // args =  "tcp://127.0.0.1:5555" ;
            string endpoint = args;

            // Create
            using (var context = new ZContext())
                using (var requester = new ZSocket(context, ZSocketType.REQ))
                {
                    // Connect
                    requester.Connect(endpoint);
                    //for (int n = 0; n < 1; n++)
                    //{
                    string requestText = Who.ToString() + "|" + Id;
                    Console.WriteLine("Отправил, что я: {0} и мой Id: {1}", Who, Id);

                    // Send
                    requester.Send(new ZFrame(requestText));


                    // Receive
                    using (ZFrame reply = requester.ReceiveFrame())
                    {
                        roomBox.Text = reply.ReadString();
                        _port2       = roomBox.Text;
                        _port1       = (Int32.Parse(_port1) + 1).ToString();
                        Console.WriteLine(" Получил: {0} {1}", requestText, roomBox.Text);
                    }
                    //roomBox.Text = reply.ReadString();
                    //_port1 = requestText;
                    //}
                    requester.Close();
                    context.Dispose();
                }
        }
示例#5
0
 public void Dispose()
 {
     loop = false;
     sink.Close();
     sink.Dispose();
     context.Shutdown();
     context.Dispose();
 }
示例#6
0
 public void Dispose()
 {
     sender.Close();
     sink.Close();
     sender.Dispose();
     sink.Dispose();
     context.Shutdown();
     context.Dispose();
 }
示例#7
0
        private void ReleaseResources()
        {
            CancelQueueThead();
            lock (requesterLock)
            {
                requester.Dispose();
            }

            context.Dispose();
        }
示例#8
0
        public void Dispose()
        {
            if (state == ServerHostState.OPEN)
            {
                // close existing sockets
                Stop();
            }

            _context.Dispose();
        }
示例#9
0
 public void Dispose()
 {
     foreach (var s in Sockets)
     {
         s.SetOption(ZSocketOption.LINGER, 0);
         s.Close();
         s.Dispose();
     }
     context.Shutdown();
     context.Terminate();
     context.Dispose();
 }
示例#10
0
 // The bulk of the clean-up code is implemented in Dispose(bool)
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         try
         {
             var keys = _feederTasks.Keys.ToList();
             foreach (var key in keys)
             {
                 RemoveTask(key);
             }
             Task.WaitAll(_waitingTasks.ToArray());
         }
         catch (AggregateException e)
         {
             Console.WriteLine("\nAggregateException thrown with the following inner exceptions:");
             // Display information about each exception.
             foreach (var v in e.InnerExceptions)
             {
                 var exception = v as TaskCanceledException;
                 if (exception != null)
                 {
                     Console.WriteLine("   TaskCanceledException: Task {0}",
                                       exception.Task.Id);
                 }
                 else
                 {
                     Console.WriteLine("   Exception: {0}", v.GetType().Name);
                 }
             }
             Console.WriteLine();
         }
         finally
         {
             foreach (var wct in _waitingCancellationToken)
             {
                 wct.Dispose();
             }
             _waitingCancellationToken.Clear();
             _waitingTasks.Clear();
             _newKeyQueue.Clear();
         }
     }
     _context.Dispose();
     // free native resources if there are any.
 }
示例#11
0
            protected void Dispose(bool disposing)
            {
                if (disposing)
                {
                    // Destructor

                    if (socket != null)
                    {
                        socket.Dispose();
                        socket = null;
                    }
                    if (context != null)
                    {
                        context.Dispose();
                        context = null;
                    }
                }
            }
示例#12
0
            protected void Dispose(bool disposing)
            {
                if (disposing)
                {
                    // Destructor
                    if (Socket != null)
                    {
                        Socket.Dispose();
                        Socket = null;
                    }

                    if (_context != null)
                    {
                        // Do Context.Dispose()
                        _context.Dispose();
                        _context = null;
                    }
                }
            }
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            /* Dispose the Python subprocess*/
            if ((python != null) && (!python.HasExited))
            {
                python.Kill();
                python.Dispose();
            }
            ;

            /* Dispose the ZMQ sockets */
            if (subscriber != null)
            {
                subscriber.Dispose();
            }
            if (publisher != null)
            {
                publisher.Dispose();
            }
            if (context != null)
            {
                context.Dispose();
            }
        }
示例#14
0
 /* Dispose the ZMQ sockets */
 public void DisposeSockets()
 {
     subscriber.Dispose();
     publisher.Dispose();
     context.Dispose();
 }
示例#15
0
 private void Disconnect()
 {
     _socket.Dispose();
     _context.Dispose();
 }
示例#16
0
 public void Dispose()
 {
     _socket.Dispose();
     _context.Dispose();
 }
示例#17
0
 public void Dispose()
 {
     responder.Dispose();
     context.Dispose();
 }
示例#18
0
 public void Dispose()
 {
     _zContext?.Dispose();
     _zSocket?.Dispose();
 }
        private void UpdateLoop(object sender, DoWorkEventArgs e)
        {
            loopActive = true;
            int loopInterval = 50;

            // Loop to get and assign elements, then update UI
            while (loopActive)
            {
                AsyncFormUpdate(new Action(() =>
                {
                    lblStatus.Text = "Update Loop Running";
                }));

                // Check to see if thread cancellation is pending
                // If true, stop the loop
                if (bwUpdateLoop.CancellationPending)
                {
                    requester.Close();
                    context.Shutdown();
                    context.Dispose();
                    requester.Dispose();
                    loopActive = false;

                    AsyncFormUpdate(new Action(() =>
                    {
                        lblStatus.Text = "Update Loop Stopped";
                    }));
                    break;
                }

                /// Socket Code
                // Send
                requester.Send(new ZFrame(_autoMode));

                try
                {
                    // Receive
                    using (ZFrame reply = requester.ReceiveFrame())
                    {
                        returnedData = JObject.Parse(reply.ToString());
                    }
                }
                catch (ZException ex)
                {
                    requester.Close();
                    context.Shutdown();
                    context.Dispose();
                    requester.Dispose();
                    loopActive = false;

                    AsyncFormUpdate(new Action(() =>
                    {
                        lblMode.Text   = "Loop Stopped";
                        lblStatus.Text = "Update Loop Stopped";
                    }));
                    break;
                }

                // ======================================================

                // Take all elements from the Dictionary and update the UI with them
                AsyncFormUpdate(new Action(() => ShowUI(returnedData)));

                // Stall the thread for a given interval to save on bandwidth
                Thread.Sleep(loopInterval);
            }

            /// update the UI with this status
            AsyncFormUpdate(new Action(() => {
                lblMode.Text = "Not Connected";
            }));
        }
示例#20
0
 public void Dispose()
 {
     requester.Dispose();
     context.Dispose();
 }
示例#21
0
 public void Dispose()
 {
     isRunning = false;
     socket?.Dispose();
     context?.Dispose();
 }
示例#22
0
 private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
 {
     routerThread.Join();
     publisher.Dispose();
     ctx.Dispose();
 }