예제 #1
0
 private void DoWebSocketKeepAlive(CancellationToken token)
 {
     WebsocketKeepAliveThread = new Thread(() =>
     {
         try
         {
             while (VoiceWebSocket.State == WebSocketState.Open && !token.IsCancellationRequested)
             {
                 if (VoiceWebSocket != null)
                 {
                     if (VoiceWebSocket.State == WebSocketState.Open)
                     {
                         string keepAliveJson = JsonConvert.SerializeObject(new
                         {
                             op = 3,
                             d  = EpochTime.GetMilliseconds()
                         });
                         VoiceDebugLogger.Log("Sending voice keepalive ( " + keepAliveJson + " ) ", MessageLevel.Unecessary);
                         VoiceWebSocket.Send(keepAliveJson);
                         Thread.Sleep(Params.heartbeat_interval);
                     }
                 }
             }
         }
         catch (NullReferenceException) { }
     });
     WebsocketKeepAliveThread.Start();
 }
예제 #2
0
        private Task DoWebSocketKeepAlive(CancellationToken token)
        {
#if NETFX4_5
            return(Task.Run(async() =>
#else
            return Task.Factory.StartNew(() =>
#endif
            {
                try
                {
                    while (VoiceWebSocket.State == WebSocketState.Open && !token.IsCancellationRequested)
                    {
                        if (VoiceWebSocket != null)
                        {
                            if (VoiceWebSocket.State == WebSocketState.Open)
                            {
                                string keepAliveJson = JsonConvert.SerializeObject(new
                                {
                                    op = 3,
                                    d = EpochTime.GetMilliseconds()
                                });
                                VoiceDebugLogger.Log("Sending voice keepalive ( " + keepAliveJson + " ) ", MessageLevel.Unecessary);
                                VoiceWebSocket.Send(keepAliveJson);
#if NETFX4_5
                                await Task.Delay(Params.heartbeat_interval);
#else
                                Thread.Sleep(Params.heartbeat_interval);
#endif
                            }
                        }
                    }
                }
                catch (NullReferenceException) { }
            }));
        }
예제 #3
0
 private Task DoWebSocketKeepAlive(CancellationToken token)
 {
     return(Task.Run(async() =>
     {
         while (VoiceWebSocket.State == WebSocketState.Open && !token.IsCancellationRequested)
         {
             if (VoiceWebSocket != null)
             {
                 if (VoiceWebSocket.State == WebSocketState.Open)
                 {
                     string keepAliveJson = JsonConvert.SerializeObject(new
                     {
                         op = 3,
                         d = EpochTime.GetMilliseconds()
                     });
                     VoiceDebugLogger.Log("Sending voice keepalive ( " + keepAliveJson + " ) ", MessageLevel.Unecessary);
                     VoiceWebSocket.Send(keepAliveJson);
                     await Task.Delay(Params.heartbeat_interval);
                 }
             }
         }
     }));
 }