Calling a function in another thread C#

前端 未结 2 1786
再見小時候
再見小時候 2020-12-21 12:42

I don\'t know how to put this but I\'ll try my best.

I have a Windows form application which uses a webcam to take a photo of a user which works fine, I\'m using the

相关标签:
2条回答
  • 2020-12-21 13:06
     Image image = (Image)pictureBox.Invoke ((Func<Image>) delegate { return pictureBox.Image; });
    
    0 讨论(0)
  • 2020-12-21 13:25

    Take a look at the SynchronizationContext class; it allows you to dispatch work back on the main (UI) thread in a manner that is agnostic of how that mechanism actually works (and therefore works with WinForms and WPF). Therefore you don't need to have a reference to a Control to call Invoke on.

    It is what BackgroundWorker uses behind the scenes (you may also be able to use BackgroundWorker, depending on what you're trying to do, which is slightly easier to work with).

    0 讨论(0)
提交回复
热议问题