Good day.

There was a problem with backgroundWorker, that is, it works at 60% and does not work at 40%, and everything happens randomly, for example, with 3 attempts to start it works, and with the next 4 it turns off at the first cycle. What could be the problem?

private void backgroundWorker1_DoWork_1(object sender, DoWorkEventArgs e) { bool BeginCycle = true; while (BeginCycle != false) { GetSensorData(); GraphMemory(); if (backgroundWorker1.CancellationPending) { BeginCycle = false; e.Cancel = true; break; } else if (!backgroundWorker1.CancellationPending) { BeginCycle = true; if (VariableVideoController.AdapterCompatibility[Form1.BufIndex] != MainClass.GetSensor.Vendor) { this.Invoke(new Action(() => textBox17.Text = "N/A")); } try { if ( VariableVideoController.AdapterCompatibility[Form1.BufIndex] == MainClass.GetSensor.Vendor) { this.Invoke(new Action(() => textBox17.Text = MainClass.GetSensor.GetGPUCore.ToString() + " MHz")); } } catch (Exception Error) { return; } } } } private void FormVideocardInfo_FormClosed(object sender, FormClosedEventArgs e) { backgroundWorker1.CancelAsync(); } 
  • one
    @ SergD29: You have a lot of code. Could you reduce the example to a minimum? For example, are all text boxes so important for understanding your problem? Also getting data like GetSensorData() - if it is important to describe your problem, then give the code, if not, remove it from the example. - VladD
  • one
    @ SergD29: No problems with this code. Show exactly how you run it. - VladD
  • one
    Thanks figured it out, forgot to free up resources chart1: if (backgroundWorker1.CancellationPending) {BeginCycle = false; e.Cancel = true; this.Invoke (new Action (() => chart1.Dispose ())); return; } but it's still not clear why he had such a percentage of work. - SergD29
  • @ SergD29 " but still it is not clear why he had such a percentage of work " problems of multithreading. Your CEP. - Dmitry Chistik

1 answer 1

 if (backgroundWorker1.CancellationPending) { BeginCycle = false; e.Cancel = true; this.Invoke(new Action(() => chart1.Dispose())); return; }