void YourMethod() { if (btnSearch.Text == "Search") { srch = new Searcher(); srch.Search(); btnSearch.Text = "Cancel"; return; } if (btnSearch.Text == "Cancel") { srch.Cancel(); } }
public void Cancel(bool cancelYoutubeUploader) { LOGGER.Debug($"Received cancel request"); if (State == RunningState.Running) { LOGGER.Info($"Cancelling auto uploader"); State = RunningState.CancelPending; Uploader.StopAfterCompleting = true; Searcher.Cancel(); DirectoryWatcher.Cancel(); if (cancelYoutubeUploader) { LOGGER.Info($"Cancelling youtube uploader"); Uploader.CancelAll(); } RefreshState(); } }