Disable All Events on a Windows Form

后端 未结 5 788
忘了有多久
忘了有多久 2021-01-19 15:21

Is there any way to temporarily disable ALL events on an windows form?

I have situation where processing on a secondary thread is being corrupted by events on the

5条回答
  •  有刺的猬
    2021-01-19 16:21

    This is a standard threading problem. Even if you could block the events, very hard to do, it still won't solve the problem. Because the event handler might already have started, but not yet finished, by the time you want to start blocking.

    And it has a standard solution, use the lock keyword.

    If that is not practical because the user needs to change several controls before you can run a query again then you need to terminate the running thread first. BackgroundWorker.CancelAsync for example. If that's not practical because it takes too long to cancel the query then you need to set the controls Enabled property to false while the query is running.

提交回复
热议问题