Async Callback causes Windows Forms events to not fire

Hi,

I'm not sure where to post this so I've posted it here and on the Web Services forum as it involves both. I will try to explain this as quickly and as best I can. If it anything doesn't make sense then by all means, please ask for more details.

I'm writing a little messager-style app whereby the app fetches messages from a web service. If a new message is returned the data library fires off a NewMessagesArrived event which is picked up by the main Library, which then instantiates and displays a little popup. Everything works fine if the message is fetched synchronously. The NewMessagesArrived event is fired, the popup is created and then it appears fine.

However, being a GUI app, to avoid unresposive behaviour I need to fetch the messages asynchronously. Everything seems to work fine; The Asynccallback fires, which then fires the EndX method to get the results, it reads the results fine, the NewMessageArrived event fires, the library creates the popup and then tries to display it. But, the popup never shows. The reason for this is that the timer event used to animate the popup never fires.

Originally, I was using a Windows Forms timer, so I tried changing that to a different timer. This worked, and the popup then appeared fine, However, the MouseEnter and MouseLeave events on the popup form stopped working. Which leads me to believe that all WindowsForms based events don't fire if the calling stack initiates out of the Callback from an asynchornous method.

If I have a button on the main form that runs the same code that would be run on the NewMessagesArrived event, then the popup works fine. Its only when the code to create, and display the popup originates from an async callback that the events don't work.

Any suggestions as to how I can fix this problem (i.e. how I can get the form events on the popup to work if/when I create the popup as a result of the async callback being fired)

Many thanks and kind regards,
Brian


Answer this question

Async Callback causes Windows Forms events to not fire

  • Async Callback causes Windows Forms events to not fire