Coap.Proxy.ClientConnection.PerformObserve C# (CSharp) Method

PerformObserve() private method

private PerformObserve ( Request method, Uri uri ) : void
method Request
uri System.Uri
return void
        private void PerformObserve(Request.Method method, Uri uri)
        {
            if (null != _currentRequest)
                _currentRequest.Cancel();

            Request request = Request.Create(method);
            _currentRequest = request;
            request.URI = uri;
            request.AddOption(Option.Create(OptionType.Observe, 60));
            request.Token = TokenManager.Instance.AcquireToken(false);
            request.Responded += new EventHandler<ResponseEventArgs>(observe_Responded);
            _observingRequest = request;
            
            //try Websocket connect
            try
            {
                //wait for websocket connect
                Thread.Sleep(5000);
                observedSession = coapWebSocektService.SessionList[coapWebSocektService.SessionList.Count - 1];
                request.ResponseQueueEnabled = true;
                request.Execute();
            }
            catch
            {
                _observingRequest.RemoveOptions(OptionType.Observe);
                _observingRequest.Execute();
                _observingRequest = null;
                Console.WriteLine("Bad websocket connect");
                this.clientSocket.Send(Encoding.UTF8.GetBytes("Bad websocket connect"));
                this.clientSocket.Disconnect(false);
                this.clientSocket.Dispose();
            }            
        }
        //on receive observe response