Curious about WinForm Control Thread Safety After Adding a Control on a Seperate Thread

前端 未结 3 1715
不思量自难忘°
不思量自难忘° 2021-01-22 07:24

I have a FileSystemWatcher set to pick up an picture that will be dropped in a particular directory. The way I was handling it was to add a PictureBox in code that is docked in

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-22 08:28

    Set Control::CheckForIllegalCrossThreadCalls to true in the beginning of the program. In this case, every cross-thread operation with Windows Forms immediately crashes the program. This is better than default undefined behavior, when CheckForIllegalCrossThreadCalls is false.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.checkforillegalcrossthreadcalls.aspx

提交回复
热议问题