BiomePainter.Batch.Batch_FormClosing C# (CSharp) Method

Batch_FormClosing() private method

private Batch_FormClosing ( object sender, FormClosingEventArgs e ) : void
sender object
e FormClosingEventArgs
return void
        private void Batch_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (worker != null && worker.IsAlive)
            {
                DialogResult res = MessageBox.Show(this, "Work hasn't completed yet. Are you sure you want to cancel?", "Biome Painter", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                if (res == DialogResult.Yes)
                {
                    btnCancel.Enabled = false;
                    mutex.WaitOne();
                    worker.Abort();
                    mutex.ReleaseMutex();
                    mutex.Dispose();
                    return;
                }
                else
                {
                    e.Cancel = true;
                    return;
                }
            }
            else if(mutex != null)
            {
                mutex.WaitOne();
                mutex.ReleaseMutex();
                mutex.Dispose();
            }
        }