public async Task <bool> ConnectAsync(Uri serviceAddress)
        {
            if (this.websocketManager == null)
            {
                this.websocketManager = new WebSocketManager();
            }

            return(await this.websocketManager.ConnectAsync(serviceAddress));
        }
        public async Task CloseAsync()
        {
            try
            {
                if (this.websocketManager != null)
                {
                    await this.websocketManager.CloseAsync();

                    this.websocketManager.Dispose();
                }
            }
            finally
            {
                this.websocketManager = null;
            }
        }
 public void Dispose()
 {
     try
     {
         this.CloseAsync().Wait();
     }
     catch (ObjectDisposedException)
     {
     }
     catch (AggregateException ae)
     {
         ae.Handle(ex => { return(true); });
     }
     finally
     {
         this.websocketManager = null;
     }
 }