Cross-thread operation not valid: Control ‘Button1’ accessed from a thread other than the thread it was created on.

今日在嘗試用Threading 寫一個線程的功能是
出現以下的Error Message

“Cross-thread operation not valid: Control ‘Button1’ accessed from a thread other than the thread it was created on.”

之後回想起之前用BackGroundWorker 時也遇過相同的問題
解決方法很簡單:
就是在 Form.Load Event 或 當你初始化你的Form
加入以下的程式碼

Control.CheckForIllegalCrossThreadCalls = False

Hope your find it useful

One thought on “Cross-thread operation not valid: Control ‘Button1’ accessed from a thread other than the thread it was created on.

Leave a Reply