开发者

Are .NET window form events (e.g. button click) synchronous or asynchronous?

My understanding is that they are synchronous, however in the project I am currently working on, when I double click on a button it ends up ca开发者_开发技巧lling the method twice, but the seconds call is made before the long running first call returns.

I know that I can prevent this by disabling the button on the first click, but I'd like to know if they are sync or async?

Thanks, Canice.


This all depends how the Window Form was setup and programmed. If the UI is running in it's own thread or the button clicks are wired up to run as a background request you would see them as Async events. However if they weren't wired up this way, they you will see them as Sync events.

So with out knowing more about how this Windows Form was programmed, the answer is it depends.


They are synchronous but not serialized. There is the possibility of reentrancy.

It sounds like your button click handler runs a nested message loop, directly or indirectly. In this case, the handler can be invoked again before the first one returns.


By default, not usually, although the way the windows message pump works may sometimes simulate it. Of course it also depends on how you define "synchronous" and "asynchronous".

In general, when you click a button, the GUI thread does not usually return until the method and any synchronous methods it calls are done. This is why the UI will "freeze up" when doing cpu intensive work in an event handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜