Esempio n. 1
0
        /// <summary>
        /// Terminate the result thread and apply any required exit procedures like sending final results.
        /// </summary>
        public override void Exit()
        {
            // Only process the logs once
            if (!ExitTriggered)
            {
                Log.Trace("BacktestingResultHandler.Exit(): starting...");
                List <LogEntry> copy;
                lock (LogStore)
                {
                    copy = LogStore.ToList();
                }
                ProcessSynchronousEvents(true);
                Log.Trace("BacktestingResultHandler.Exit(): Saving logs...");
                var logLocation = SaveLogs(_algorithmId, copy);
                SystemDebugMessage("Your log was successfully created and can be retrieved from: " + logLocation);

                // Set exit flag, update task will send any message before stopping
                ExitTriggered = true;
                ExitEvent.Set();

                StopUpdateRunner();

                SendFinalResult();

                base.Exit();
            }
        }
Esempio n. 2
0
        private void check()
        {
            bool bConnected;
            int  nWaitIndex = WaitHandle.WaitTimeout;

            do
            {
                bConnected = socket.IsConnected();
            }while (bConnected && ((nWaitIndex = WaitHandle.WaitAny(_events, ConnectionCheckingTime)) == WaitHandle.WaitTimeout));

            if (nWaitIndex == 1 || !bConnected)// connection error
            {
                Debug.WriteLine("Connection lost");
                IPEndPoint iep = socket.ServerEndPoint;

                IPEndPoint nextEndPoint = removeAndGetNextEndpoint(iep);
                if (nextEndPoint != null)
                {
                    Connect(nextEndPoint);
                }
                else
                {
                    ExitEvent.Set();
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Gracefully stops the OpenVPN process, notifying the server of the disconnect
 /// </summary>
 /// <param name="wait">Wait for the process to exit</param>
 public static void SoftKill(bool wait = false)
 {
     EventRegistrar.Status.OnStatusUpdate("Stopping OpenVPN container...");
     if (!IsRunning)
     {
         return;
     }
     ExitEvent.Set();
     if (wait)
     {
         OpenVpnContainerProcess.WaitForExit(10000);
     }
 }
Esempio n. 4
0
        async Task MainLoopAsync(CancellationToken cancel)
        {
            await Task.Yield();

            try
            {
                // 終了するまで待機する (Cancel された場合は Kill されるので以下の待機は自動的に解除される)
                Proc.WaitForExit();
                if (this.EndTick == 0)
                {
                    this.EndTick = Time.HighResTick64;
                }
            }
            catch (Exception ex)
            {
                if (this.EndTick == 0)
                {
                    this.EndTick = Time.HighResTick64;
                }
                ex._Debug();
                throw;
            }
            finally
            {
                if (this.EndTick == 0)
                {
                    this.EndTick = Time.HighResTick64;
                }

                // 終了した or 待機に失敗した
                // 戻り値をセットする
                try
                {
                    _ExitCode = Proc.ExitCode;
                }
                catch
                {
                    _ExitCode = -1;
                }

                if (this.EasyInputTask != null)
                {
                    await this.EasyInputTask._TryAwait();
                }

                try
                {
                    if (this.EasyOutputTask != null)
                    {
                        this._EasyOutputData = await this.EasyOutputTask;
                    }

                    if (this.EasyErrorTask != null)
                    {
                        this._EasyErrorData = await this.EasyErrorTask;
                    }
                }
                catch (Exception ex)
                {
                    ex._Debug();
                }

                if (this.EasyRealtimeBufferMainteTask != null)
                {
                    await this.EasyRealtimeBufferMainteTask._TryWaitAsync();
                }

                EasyOutputAndErrorDataCompleted = true;

                Interlocked.MemoryBarrier();

                // 完了フラグを立てる
                ExitEvent.Set(true);
            }
        }