Esempio n. 1
0
        public void Abort_WithTimeout_AbortsWithoutException()
        {
            using (var sut = new AbortableWorker(() => { Thread.Sleep(60000); return true; }))
            {
                sut.Start();
                sut.ResumeWork();
                sut.Abort(400);
                sut.ThreadInstance.Join();

                Assert.True(sut.Aborted);
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            int retriesBefore = 0;

            if (_useRetries)
            {
                retriesBefore = _retries;
                _retries      = 1;
            }

            _stop = true;
            _worker.Abort();
            if (_useRetries)
            {
                _retries = retriesBefore;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Form closing event
        /// </summary>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //If any workers are running, display a prompt
            AbortableWorker worker = this.wokers.Find(w => w.IsBusy);

            if (worker != null)
            {
                //Display prompt
                DialogResult prompt = MessageBox.Show(this, "The simulation is still running in the background, are you sure you want to close the form now?",
                                                      "Simulation running!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);

                switch (prompt)
                {
                //If user continues to close, abort working thread
                case DialogResult.Yes:
                    worker.Abort(); break;

                //Else cancel closing event
                case DialogResult.No:
                    e.Cancel = true; break;
                }
            }
        }