/// <summary> /// Stops the background worker. /// </summary> private void ScannerFormClosing(object sender, FormClosingEventArgs e) { if (!_isLoadingNow) { return; } // Cancels the asynchronous operation. BgWorker.CancelAsync(); e.Cancel = true; }
/// <summary> /// Check whether the strategy have been changed. /// </summary> private void OptimizerFormClosing(object sender, FormClosingEventArgs e) { if (!_isReset) { SaveOptions(); } if (_isOptimizing) { // Cancel the asynchronous operation. BgWorker.CancelAsync(); e.Cancel = true; return; } if (DialogResult == DialogResult.Cancel && _isStartegyChanged) { DialogResult dr = MessageBox.Show(Language.T("Do you want to accept changes to the strategy?"), Language.T("Optimizer"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (dr) { case DialogResult.Cancel: e.Cancel = true; return; case DialogResult.Yes: DialogResult = DialogResult.OK; break; case DialogResult.No: DialogResult = DialogResult.Cancel; break; } } else if (DialogResult == DialogResult.OK && !_isStartegyChanged) { DialogResult = DialogResult.Cancel; } FormFSB.Visible = true; }
private void BgWorker_DoWork(object sender, DoWorkEventArgs e) { int showProgressEnableCounter = 0; //sync do var task = Task.Factory.StartNew(() => { var updateResult = ServiceClient.UploadFile(this.DestFileName, "", tokenSource.Token); if (!updateResult) { IsSuccess = false; MessageBox.Show($"upload { this.DestFileName} fail"); } //delete client file File.Delete(this.DestFileName); }).ContinueWith(t => BgWorker.CancelAsync()); int k = 0; while (true) { if (BgWorker.CancellationPending) { e.Cancel = true; break; } Interlocked.Increment(ref showProgressEnableCounter); if (k == showProgressEnableCounter / 1000000) { continue; } k = showProgressEnableCounter / 1000000; if (k > 100) { showProgressEnableCounter = 0; } BgWorker.ReportProgress(k); } }
/// <summary> /// Starts intrabar data loading. /// </summary> private void StartLoading() { if (_isLoadingNow) { // Cancel the asynchronous operation. BgWorker.CancelAsync(); return; } Cursor = Cursors.WaitCursor; ProgressBar.Value = 0; _warningMessage = string.Empty; _isLoadingNow = true; _progressPercent = 0; LblProgress.Visible = true; ChbAutoscan.Visible = false; ChbTickScan.Visible = false; BtnClose.Text = Language.T("Cancel"); // Start the bgWorker BgWorker.RunWorkerAsync(); }
public void Cancel() { BgWorker.CancelAsync(); }
/// <summary> /// Cancels the log's processing /// </summary> public void Cancel() { Status = "Cancelling..."; Metadata.State = RowState.Cancelling; BgWorker.CancelAsync(); }
// _____ _ _ _ _____ _ _ ____ _ _ // / ____| (_) | | / ____| | | | | _ \ | | | | // | | | |_ ___| | __ | (___ | |_ __ _ _ __| |_ | |_) |_ _| |_| |_ ___ _ __ // | | | | |/ __| |/ / \___ \| __/ _` | '__| __| | _ <| | | | __| __/ _ \| '_ \ // | |____| | | (__| < ____) | || (_| | | | |_ | |_) | |_| | |_| || (_) | | | | // \_____|_|_|\___|_|\_\ |_____/ \__\__,_|_| \__| |____/ \__,_|\__|\__\___/|_| |_| private void StartButton_Click(object sender, EventArgs e) { if (BgWorker.IsBusy) { BgWorker.CancelAsync(); return; } string tokenstring = TokenTextbox.Text; tokenstring = tokenstring.Replace("\r\n", "\n").Replace('\r', '\n'); tokenstring = tokenstring.Replace("\n", Environment.NewLine); tokenstring = tokenstring.Trim(Environment.NewLine.ToCharArray()); string triplenewline = Environment.NewLine + Environment.NewLine + Environment.NewLine; string doublenewline = Environment.NewLine + Environment.NewLine; while (tokenstring.Contains(triplenewline)) { tokenstring = tokenstring.Replace(triplenewline, doublenewline); } TokenTextbox.Text = tokenstring; //make sure the user has entered at least one thing if (TokenTextbox.Lines.Length == 0) { MessageBox.Show("You must enter at least one token.", "No Tokens Entered", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (LastColumnComboBox.SelectedIndex <= FirstColumnComboBox.SelectedIndex) { MessageBox.Show("Your \"Vector End\" column needs to come after\r\nyour \"Vector Start\" column.", "Invalid vector range", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Enabled = false; FolderBrowser.SelectedPath = Path.GetDirectoryName(openFileDialog.FileName); if (FolderBrowser.ShowDialog() != DialogResult.Cancel) { BgWorkerInformation BgData = new BgWorkerInformation(); BgData.InputFile = FilenameDisplayBox.Text; BgData.OutputLocation = FolderBrowser.SelectedPath.ToString(); BgData.HasHeaders = HeaderRowDropdown.SelectedItem.ToString(); BgData.Delimiters = DelimiterTextBox.Text.ToString(); BgData.UsingQuotes = EnclosedInQuotesDropdown.SelectedItem.ToString(); BgData.TokenCol = TokenColumnComboBox.SelectedIndex; BgData.StartingCol = FirstColumnComboBox.SelectedIndex; BgData.EndingCol = LastColumnComboBox.SelectedIndex; //here, we have to go through some steps to get our user-submitted word list into //separate chunks. First, we figure out where empty linebreaks occur List <int> split_indices = new List <int>(); int lastIndex = 0; while ((lastIndex = Array.IndexOf(TokenTextbox.Lines, "", lastIndex)) != -1) { split_indices.Add(lastIndex); lastIndex++; } //now, we set up an array of lists so that we can assign tokens to each //list List <string>[] token_list_array = new List <string> [split_indices.Count() + 1]; for (int i = 0; i <= split_indices.Count(); i++) { token_list_array[i] = new List <string>(); } string[] TokenTextbox_As_Array = TokenTextbox.Lines; //now, we do the assigning int split_position = 0; for (int i = 0; i < TokenTextbox_As_Array.Length; i++) { if (split_position < split_indices.Count() && i >= split_indices[split_position]) { split_position++; continue; } token_list_array[split_position].Add(TokenTextbox_As_Array[i]); } BgData.Tokens = new HashSet <string> [token_list_array.Length]; for (int i = 0; i < token_list_array.Length; i++) { BgData.Tokens[i] = new HashSet <string>(token_list_array[i].Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); } //we use "distinct" because we can't have dupes in a hashset BgData.Tokens_Altogether = new HashSet <string>(TokenTextbox.Lines.Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); BgData.OmitBelowValue = 1.0 - ((OmissionValueComboBox.SelectedIndex + 1.0) / 10.0); DisableButtons(); StartButton.Text = "Cancel"; try { using (StreamWriter outputFile = new StreamWriter(new FileStream(Path.Combine(BgData.OutputLocation, "_WELP_SeedList.txt"), FileMode.Create, FileAccess.Write), Encoding.GetEncoding(EncodingDropdown.SelectedItem.ToString()))) { outputFile.Write(TokenTextbox.Text); } } catch { MessageBox.Show("There was an error writing your seed list to the" + "\r\n" + "output directory. Please check all of your settings" + "\r\n" + "and folders before starting again.", "Output Write Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Enabled = true; StartButton.Text = "Start!"; EnableButtons(); return; } BgWorker.RunWorkerAsync(BgData); } this.Enabled = true; }
// _____ _ _ _ _____ _ _ ____ _ _ // / ____| (_) | | / ____| | | | | _ \ | | | | // | | | |_ ___| | __ | (___ | |_ __ _ _ __| |_ | |_) |_ _| |_| |_ ___ _ __ // | | | | |/ __| |/ / \___ \| __/ _` | '__| __| | _ <| | | | __| __/ _ \| '_ \ // | |____| | | (__| < ____) | || (_| | | | |_ | |_) | |_| | |_| || (_) | | | | // \_____|_|_|\___|_|\_\ |_____/ \__\__,_|_| \__| |____/ \__,_|\__|\__\___/|_| |_| private void StartButton_Click(object sender, EventArgs e) { if (BgWorker.IsBusy) { BgWorker.CancelAsync(); return; } int number_of_columns = ColumnNameCheckedListbox.CheckedIndices.Count; if (number_of_columns < 1) { MessageBox.Show("You must choose at least one column to keep.", "No columns selected", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //validate the subfolder numbers this.Enabled = false; FolderBrowser.Description = "Please choose the OUTPUT location for your files"; FolderBrowser.SelectedPath = Path.GetDirectoryName(openFileDialog.FileName); if (FolderBrowser.ShowDialog() != DialogResult.Cancel) { BgWorkerInformation BgData = new BgWorkerInformation(); BgData.InputFile = FilenameDisplayBox.Text; BgData.OutputLocation = FolderBrowser.SelectedPath.ToString(); BgData.HasHeaders = HeaderRowDropdown.SelectedItem.ToString(); BgData.Delimiters = DelimiterTextBox.Text.ToString(); BgData.UsingQuotes = EnclosedInQuotesDropdown.SelectedItem.ToString(); List <int> CheckedIndices = new List <int>(); foreach (Object item in ColumnNameCheckedListbox.CheckedItems) { CheckedIndices.Add(ColumnNameCheckedListbox.Items.IndexOf(item)); } BgData.KeepCols = CheckedIndices.ToArray(); BgData.NumberOfColumns = BgData.KeepCols.Length; DisableButtons(); StartButton.Text = "Cancel"; BgWorker.RunWorkerAsync(BgData); } this.Enabled = true; }
/// <summary> /// BtnGenerate_Click /// </summary> private void BtnGenerateClick(object sender, EventArgs e) { if (_isGenerating) { // Cancel the asynchronous operation BgWorker.CancelAsync(); } else { // Start the bgWorker PrepareStrategyForGenerating(); CheckForLockedSlots(); PrepareIndicatorLists(); bool isEnoughIndicators = CheckAvailableIndicators(); if (_isEntryLocked && _isExitLocked || !isEnoughIndicators) { SystemSounds.Hand.Play(); return; } Cursor = Cursors.WaitCursor; _minutes = (int)NUDWorkingMinutes.Value; ProgressBar.Style = _minutes > 0 ? ProgressBarStyle.Blocks : ProgressBarStyle.Marquee; GeneratedDescription = String.Empty; foreach (Control control in PnlCommon.Controls) { control.Enabled = false; } foreach (Control control in PnlLimitations.Controls) { control.Enabled = false; } foreach (Control control in PnlSettings.Controls) { control.Enabled = false; } IndicatorsField.BlockIndicatorChange(); TsbtLockAll.Enabled = false; TsbtUnlockAll.Enabled = false; TsbtLinkAll.Enabled = false; TsbtOverview.Enabled = false; TsbtStrategyInfo.Enabled = false; LblCalcStrInfo.Enabled = true; LblCalcStrNumb.Enabled = true; ChbHideFSB.Enabled = true; BtnAccept.Enabled = false; BtnCancel.Enabled = false; BtnGenerate.Text = Language.T("Stop"); _isGenerating = true; ProgressBar.Value = 1; _progressPercent = 0; _cycles = 0; if (ChbGenerateNewStrategy.Checked) { Top10Field.ClearTop10Slots(); } BgWorker.RunWorkerAsync(); } }
/// <summary> /// Cancels the log's processing /// </summary> public void Cancel() { State = RowState.Cancelling; BgWorker.CancelAsync(); }
/// <summary> /// Optimize. /// </summary> private void BtnOptimizeClick(object sender, EventArgs e) { if (_isOptimizing) { // Cancel the asynchronous operation. BgWorker.CancelAsync(); return; } if (ChbOptimizerWritesReport.Checked) { InitReport(); } // Counts the checked parameters _checkedParams = 0; for (int i = 0; i < _parameters; i++) { if (AchbxParameterName[i].Checked) { _checkedParams++; } } // If there are no checked returns if (_checkedParams < 1) { SystemSounds.Hand.Play(); return; } // Contains the checked parameters only _aiChecked = new int[_checkedParams]; int indexChecked = 0; for (int i = 0; i < _parameters; i++) { if (AchbxParameterName[i].Checked) { _aiChecked[indexChecked++] = i; } } SetNecessaryCycles(); Cursor = Cursors.WaitCursor; ProgressBar.Value = 1; _progressPercent = 0; _computedCycles = 0; _isOptimizing = true; BtnCancel.Enabled = false; BtnAccept.Enabled = false; BtnOptimize.Text = Language.T("Stop"); for (int i = 0; i <= (int)OptimizerButtons.ResetStrategy; i++) { AOptimizerButtons[i].Enabled = false; } foreach (Control control in PnlParams.Controls) { if (control.GetType() != typeof(Label)) { control.Enabled = false; } } foreach (Control control in PnlLimitations.Controls) { control.Enabled = false; } foreach (Control control in PnlSettings.Controls) { control.Enabled = false; } ChbHideFSB.Enabled = true; // Start the bgWorker BgWorker.RunWorkerAsync(); }