Exemple #1
0
        protected override void KeepAliveMonitor()
        {
            while (!IsTerminated)
            {
                try
                {
                    if (!IsConnected)
                    {
                        Log(Level.Info, false, $"Disconnect detected");
                        ConnectAndOpen();
                    }
                    else if (IsInvalidConnection)
                    {
                        IsConnected = false;
                        break;
                    }
                    else if ((LastUpdateTime != DateTime.MinValue) && (DateTime.Now - LastUpdateTime) > TimeSpan.FromMinutes(CurrentParams.TimeoutMinutes))
                    {
                        Log(Level.Info, false, $"Timeout detected");
                        Close();
                        ConnectAndOpen();
                    }

                    if (IsConnected && !IsTerminated && !isUpdating)
                    {
                        if (updateHandler == null || TaskEndedStatuses.Any(s => updateHandler.Status == s))
                        {
                            updateHandler = Task.Factory.StartNew(() => { UpdateParameters(); }, TaskCreationOptions.LongRunning);
                        }
                    }
                }
                catch (Exception ex) { Log(ex); }

                Task.Delay(1000).Wait();
            }
            Task.Factory.StartNew(() =>
            {
                Task.Delay(0).Wait();
                try { keepAliveHandler.Dispose(); }
                catch { }
                keepAliveHandler = null;
            });
        }
Exemple #2
0
        public override void ConnectAndOpen()
        {
            IsLogin = false;
            base.ConnectAndOpen();

            if (IsConnected && !IsTerminated)
            {
                if (updateHandler == null || TaskEndedStatuses.Any(s => updateHandler.Status == s))
                {
                    updateHandler = Task.Factory.StartNew(() => { UpdateParameters(); }, TaskCreationOptions.LongRunning);
                }

                while (!IsLogin && !IsInvalidConnection)
                {
                    SendLogin();
                    while (IsConnected && !IsLogin && !IsInvalidConnection)
                    {
                        Task.Delay(100).Wait();
                    }
                }
            }
        }