Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

Welcome, Guest
Guest Settings

Thread: Removing listener of specific event on IBEvents.onEventAlert

This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Permlink Replies: 0
Elton Barbosa

Posts: 9
Registered: 7/19/00
Removing listener of specific event on IBEvents.onEventAlert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2016 11:27 AM
Some time ago, I did asked how I could remove an event from the list of events when an onEventAlert occur. I do not need one event to be listened more than one time.
The list of events are a StringList, but to change the registered events I need to call RegisterEvents or UnRegisterEvents.
As help still explain, this is not possible in the onEventAlert because "you cannot call call RegisterEvents, UnRegisterEvents, GetAutoRegister or SetAutoRegister from within an OnEventAlert event handler". In true, the application freeze if you try to do so.
I couldn't find the original question. But I found this mirror:

One suggestion I got (from Jeff Overcash) was that I could be able to remove it from the stringlist, then Post a custom message that your form listens for. It should finish your event handler then process the message queue, pick up your custom message and you can unregister re-resgister based on the stringlist as it exists after you modified it in the event handler.

But now I wanted to isolate this part of code from my application, creating a class that should do this without interference. So I changed the code that create the message to create an anonymous thread and run the code that would be called from the custom message. This is working fine on tests.

The question is, could this lead to any race condition or hard to solve problem? If so, what could I do instead to isolate the code that unregister/re-register the events from the main code?
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02