InvalidOperationException - object is currently in use elsewhere

前端 未结 4 1212
再見小時候
再見小時候 2020-11-28 13:25

I\'ve gone through this SO question but it didn\'t help.

The case here is different. I\'m using Backgroundworkers. 1st backgroundworker starts operating on the image

4条回答
  •  清酒与你
    2020-11-28 13:47

    In windows forms not only should you only access the controls from a single thread but that thread should be the main application thread, the thread that created the control.

    This means that in DoWork you should not access any controls (without using Control.Invoke). So here you would call RunWorkerAsync passing in your image clone. Inside the DoWork event handler, you can extract the parameter from the DoWorkEventArgs.Argument.

    Only the ProgressChanged and RunWorkerCompleted event handlers should interact with the GUI.

提交回复
热议问题