示例#1
0
        /// <summary>
        /// ボナンザを停止します。
        /// </summary>
        public void Abort(AbortReason reason, int millis = 500)
        {
            using (LazyLock())
            {
                this.aborted = true;

                // 初期化されていなければ、そのまま帰ります。
                if (!this.initialized)
                {
                    return;
                }

                WriteCommand("quit");

                // ボナンザプロセスを終了します。
                var process = this.bonaProcess;
                if (process != null)
                {
                    if (!process.WaitForExit(millis))
                    {
                        process.Kill();
                    }

                    this.bonaProcess = null;
                }

                if (this.writeThread != null)
                {
                    this.writeThread.Join(0);
                    this.writeThread = null;
                }

                if (this.readThread != null)
                {
                    this.readThread.Join(0);
                    this.readThread = null;
                }

                if (this.errorReadThread != null)
                {
                    this.errorReadThread.Join(0);
                    this.errorReadThread = null;
                }

                this.initialized = false;
                IsConnected      = false;
                AbortedReason    = reason;
            }

            Aborted.SafeRaiseEvent(this, new BonanzaAbortedEventArgs(reason));
        }