Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod accessed by more than one thread in C# Using Progressbar
    primarykey
    data
    text
    <p>I have multiple threads accessing a method. </p> <p>That method updates the progress bar on the form as the threads execute.</p> <p>That method updates the progress bar on my windows form showing the progress of the processed files as the threads are completing them. </p> <p>How would you go about managing that method to avoid deadlocks. Im having trouble locking it, dont know if im doing it wrong, or if i should lock it in this case.</p> <pre><code>public void myWorkerClass() { int amountToScan = 4; lblcount.BeginInvoke( ((Action)(() =&gt; lblcount.Text = "Files Checked " + atPDFNumber.ToString() + " of " + amountToScan.ToString()))); decimal percentageComplete = ((decimal)atPDFNumber / (decimal)amountToScan) * 100; backgroundWorker1.ReportProgress((int)percentageComplete); } </code></pre> <p>What happens is, that at the last line, it breaks telling me that "This operation has already had OperationCompleted called on it and further calls are illegal."</p> <p>I take it that im opening something that has already been disposed by the first thread or something like that.</p> <p>Is this a good way to go about using the progress bar with multiple threads (do i have the right idea or principle), or is there just a small error in my code?</p> <p>How I want to make this question valuable for other people is to answer with this question how global variables can be accessed inside a method that's being accessed by multiple threads. since i take it thats the direction this question is going in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload