public void startAsyncWorkerWithTask(string desc, DoWorkEventHandler asyncWork, CleanupDelegate asyncCleanup, object argument) { if (!asyncWorker.IsBusy) { if (USB.Check_Limit_Switches() && USB.IsOpen) { ExtLog.AddLine("Starting Async Task"); USB.Inhibit_LimitSwitches_Warning = true; HostControl.Enabled = false; try { ExtLog.AddLine(desc); asyncWorker.DoWork += asyncWork; lastTask = asyncWork; CleanupCallback = asyncCleanup; asyncWorker.RunWorkerAsync(argument); } catch (Exception ex) { ExtLog.AddLine("Async Task failed: " + ex.Message); } ExtLog.AddLine("Async Started"); if (taskDialog.ShowDialog(HostControl) == DialogResult.Abort) { cancelTask(); USB.CancelMove(); } HostControl.Enabled = true; USB.Inhibit_LimitSwitches_Warning = false; } else { ExtLog.AddLine("Can't init scripted sequence, limit switches are not properly set or USB interface is Closed"); } } else { ExtLog.AddLine("Async Task Already Running"); } }
private void AbortMoveButton_Click(object sender, EventArgs e) { USB.CancelMove(); }