The calling thread cannot access this object because a different thread owns it.WPF

后端 未结 6 822
一向
一向 2020-11-28 10:16

Whenever I refresh a label, I got this error: The calling thread cannot access this object because a different thread owns it. I tried to invoke b

6条回答
  •  孤城傲影
    2020-11-28 10:24

    Several suggestions to use BeginInvoke, but no mention of EndInvoke. Good Practice is that 'every BeginInvoke has a matching EndInvoke' and certainly there needs to be some safeguard against race conditions (Think: what happens with multiple BeginInvoke of code but none have finished processing yet?)

    It's easy to forget, and I've seen this error (and, yes, it is an error) in both MSDN examples and published books on WinForms

提交回复
热议问题