Jump to content
Fulgan

Issue with several TOmniContainerWindowsMessageObserver for the main thread

Recommended Posts

Hello,

 

I have an issue with the TOmniContainerWindowsMessageObserver and observers in general.

 

I use one instance of TOmniMessageQueue to send data from a background thread to the main thread. However, it happens that several window are interested in receiving messages from the queue.

 

So, I setup things like this: each form will create a TOmniContainerWindowsMessageObserver observer and attach it to the TOmniMessageQueue like this during the form's show event:

 

    MQObserver := CreateContainerWindowsMessageObserver(handle, WM_NEW_ITEM, 0, 0); // Create an observer that will notify the main form when new messages are received
    UserMessageQueue.ContainerSubject.Attach(MQObserver, coiNotifyOnAllInserts); // attach the observer to the message queue

 

Likewise, when the form closes, the observer is detached and destroyed:

    UserMessageQueue.ContainerSubject.Detach(MQObserver, coiNotifyOnAllInserts);
    // we don't need the observer anymore
    FreeAndNil(MQObserver);

My problem is that as soon as one observer is detached from the queue, all other observer stops notifying the other windows of the fact that a new message has been inserted.

 

What am I missing here?

 

Share this post


Link to post

I don't understand how that should work. "Several windows are interested in receiving messages from the queue" - are they then fighting to fetch that message? 

 

It is quite possible that something goes wrong in such case. I don't believe I ever tested such setup.

 

Can you get me a sample program so I can repeat the problem?

Share this post


Link to post
Quote

I don't understand how that should work. "Several windows are interested in receiving messages from the queue" - are they then fighting to fetch that message? 

No, they just get notified that a new message has arrived and can request it the from the object that manages the queue.

 

Quote

It is quite possible that something goes wrong in such case. I don't believe I ever tested such setup.

 

Ok, thanks 🙂  I'll work something out. 

 

Quote

 Can you get me a sample program so I can repeat the problem?

 

I'll try to, sure.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×