示例#1
0
 /// <summary>
 /// 開放処理。
 /// </summary>
 public void Dispose()
 {
     if (CTS == null)
     {
         return;
     }
     CTS.Cancel();
     CTS.Dispose();
     CTS = null;
 }
示例#2
0
        /// Release any unmanaged resources
        public virtual void Dispose()
        {
            Source?.Dispose();
            Dest?.Dispose();

            CTS?.Dispose();
            Client?.Dispose();

            try
            {
                Worker?.Dispose();
            }
            catch (InvalidOperationException)
            {
                return;
            }
        }
示例#3
0
        public async Task DisconnectAsync()
        {
            if (WS is null)
            {
                return;
            }
            // TODO: requests cleanup code, sub-protocol dependent.
            if (WS.State == WebSocketState.Open)
            {
                CTS.CancelAfter(TimeSpan.FromSeconds(2));
                await WS.CloseOutputAsync(WebSocketCloseStatus.Empty, "", CancellationToken.None);

                await WS.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
            }
            WS.Dispose();
            WS = null;
            CTS.Dispose();
            CTS = null;
        }
示例#4
0
        public async Task ConnectAsync(string url)
        {
            if (WS != null)
            {
                if (WS.State == WebSocketState.Open)
                {
                    return;
                }
                else
                {
                    WS.Dispose();
                }
            }
            WS = new ClientWebSocket();
            if (CTS != null)
            {
                CTS.Dispose();
            }
            CTS = new CancellationTokenSource();
            await WS.ConnectAsync(new Uri(url), CTS.Token);

            await Task.Factory.StartNew(ReceiveLoop, CTS.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }