Accessing a form's control from a separate thread

后端 未结 5 452
Happy的楠姐
Happy的楠姐 2020-11-30 10:57

I\'m practising on threading and came across this problem. The situation is like this:

  1. I have 4 progress bars on a single form, one for downloading a file,

5条回答
  •  没有蜡笔的小新
    2020-11-30 11:46

    A Control can only be accessed within the thread that created it - the UI thread.

    You would have to do something like:

    Invoke(new Action(() =>
    {
        progressBar1.Value = newValue;
    }));
    

    The invoke method then executes the given delegate, on the UI thread.

提交回复
热议问题