Exemplo n.º 1
0
        public bool Connect(string host, ushort port, string user, string pw)
        {
            if (!_connected && !_disconnecting)
            {
                _sendQueue.Clear();
                _receiveQueue.Clear();
                _rsConnector = new RSSSHConnector(this, host, port, user, pw);
                if (_rsConnector.Connect())
                {
                    _rsProtoBuf = new RSProtoBuf(_rsConnector.Stream, _sendQueue, _receiveQueue, this);
                    _connected  = true;
                    _run        = true;

                    _t          = new Thread(new ThreadStart(ProcessNewMsgLoop));
                    _t.Name     = "Process new msg loop";
                    _t.Priority = ThreadPriority.Normal;
                    _t.Start();

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private void ShutDownThread()
        {
            byte counter = 0;

            _rsProtoBuf.FinishQueue();
            // wait 10 seconds to send all remaining items
            while (_rsProtoBuf.ThreadRunning && counter < 10 * 2)
            {
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "waiting to send remaining items - " + counter);
                Thread.Sleep(500);
                counter++;
            }
            _rsProtoBuf.StopThread();
            Thread.Sleep(100);
            if (!_useProperDisconnect)
            {
                _rsProtoBuf.BreakConnection();
            }
            _rsProtoBuf = null;
            _rsConnector.Disconnect();
            _rsConnector   = null;
            _connected     = false;
            _disconnecting = false;
        }