Reputation: 13610
My form creates a backgroundworker that every 6 secs checks something. Result is 1-100 and I want to display this.
But if i do it straight forward i get som cross-thread errors so I after some research delegates is the way to do it.
ive created inside the Form1 class:
public delegate void SetProgressbarValueDelegate(int val);
but how do i "connect it" to actually update the progressbar?
Thanks
Upvotes: 0
Views: 1097
Reputation: 70142
Assuming your are using WinForms, The BackgroundWorker
class raises a ProgressChanged event which will automatically be marshalled back onto your UI thread. You should make updates to your User Interface within your handler for this event.
There are some simple examples of how to use BackgroundWorker
within the MSDN documentation.
Upvotes: 4