开发者

Update progressbar's value from another thread?

开发者 https://www.devze.com 2023-03-18 00:50 出处:网络
My form creates a backgroundworker that every 6 secs checks something. Result is 1-100 and I want to display this.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消