I\'m a newbie with multithreading. I have a winform that have a label and a progress bar.
I wanna show the processing result. Firstly, I use Application.DoEven
There are some fundamental problems with the code you have shown. As other have mentioned, Application.DoEvents()
will not do what you want from a background thread. Separate your slow background processing into a BackgroundWorker
and update your progress bar in the UI thread. You are calling progressBar1.Value++
from a background thread, which is wrong.
Never call Control.CheckForIllegalCrossThreadCalls = false
, that will only hide errors.
If you want to update a progress bar from a background thread, you will have to implement a ProgressChanged
handler; you are not doing that.
If you need an example of implementing a BackgroundWorker
, consult the article BackgroundWorker Threads from Code Project.