Re: Synchronizing dialog's from different threads

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Wed, 24 Jun 2009 08:43:45 -0700, schaf <dlocke@xxxxxxxxxxxx> wrote:

Hi All!
I have a challenging task.
My app is split into two parts, a Base and a Main part.
Now I would like to create a controller class, which handles all
notifications (UI dialog similar to message boxes) from both parts.
The application contains multiple threads and therefore I need to
synchronize the creation of the notification to the main thread,
especially if I would like to handover the main UI-Handle to the
notification.show method.
But the first base function could send a notification before my main
UI is created. So I can not synchronize the notification to the UI
thread, neither by using Invoke nor by using the
SynchronizationContext. Is there a solution, where I can create a
SynchronizationContext for the main UI thread, before the UI creation
is finished?

Or is it not possible to synchronize such a behavior?

It really depends on your specific situation. You didn't provide any code, never mind a concise-but-complete example, so it's impossible to know for sure what would work best for you.

The main limitation on the SynchronizationContext is the same that exists for Control.Invoke(), which is that you need for there to be some kind of "dispatcher" running. Both Forms and WPF applications will have this going once the application is up and running (in Forms, for example, it occurs once the call to Application.Run() has been made, usually from the Program.Main() method).

You can emulate the same behavior yourself, but that would involve setting up a queue and a loop where you consume the elements of the queue, and then the thread that was executing that loop would never get around to starting up the UI. :) This is more appropriate for applications that need a similar behavior, but will never actually have a UI created.

It seems to me that the most obvious solution is to still make such a queue, but then simply consume the entire queue once the UI has been created. You could either make the queue special-purpose, queuing items only when you detect that the UI isn't present, or it could simply be part of your standard operating mechanism, where consumption of the queue continues to happen as the worker threads add new items during execution, even after the UI has first been created.

The queue itself could either be very specific to your application, with the elements being some data structure representing the work you want to present to the user, or it can be very general-purpose, simply containing delegates to be invoked during consumption.

If you want more specific advice than that, you'll have to be more specific about the question.

Pete
.



Relevant Pages

  • [PATCH 06/12] fsnotify: generic notification queue and waitq
    ... on a queue until the listener is ready to receive it. ... implements a generic notification queue for inotify to ... * hold real event information we just keep one system wide and use it any time ...
    (Linux-Kernel)
  • Re: Remote notification of presubmission queue exceeding set value?
    ... Why don't you use the script notification feature in ESM, ... > method of being remotely notified if the queue exceeds a set amount, ... when the SMTP service is plugged!? ... > I thought about getting another vendor's event log monitor that has it's ...
    (microsoft.public.exchange.admin)
  • Re: Sendmail ignores -N never option for DSNs?
    ... Sendmail connects to the nominated MX for the sender, ... I don't want this second part happening for the mail in the queue. ... -N dsn Set delivery status notification conditions to dsn, ...
    (comp.mail.sendmail)
  • Sendmail ignores -N never option for DSNs?
    ... Sendmail connects to the nominated MX for the sender, and sends a DSN. ... I don't want this second part happening for the mail in the queue. ... -N dsn Set delivery status notification conditions to dsn, ...
    (comp.mail.sendmail)
  • [PATCH -V2 07/13] fsnotify: generic notification queue and waitq
    ... on a queue until the listener is ready to receive it. ... implements a generic notification queue for inotify to ... extern struct list_head fsnotify_groups; ... * hold real event information we just keep one system wide and use it any time ...
    (Linux-Kernel)