views:

60

answers:

1

I am in the process of teaching myself thread based programming techniques and this question may be way off base... I'm not even sure if this is possible or indeed even the right approach to this problem. Please feel to correct me in what question I should be asking if appropriate.

I am trying to have a certain thread deal with an event (asides from the thread that fires the event) but I am not wanting the UI thread to handle it. To be clear I am not looking to do this:

private void UpdateFromNewFrame(WindowFrame frame) {

    if (InvokeRequired) {
         BeginInvoke(new WindowUpdateHandler(UpdateFromNewFrame), new object[] { frame });
         return;
    }

    Text = frame.Title;
}

I am looking for a way create the same pattern but with a non ui thread. The reason is that I have to (under infrequent circumstances) carry out some lengthy processing which delays the thread firing the event (and other events listeners after this event listener).

Is it even possible to invoke a thread or should I be creating a new thread within the event listener or is there some way to have the event listeners all called in separate (automatically created) threads?

+1  A: 

The non-UI thread would have to have some sort of message-processing loop, just as the UI thread does. It would wait to receive items to process, and process them accordingly. That's fairly easy to do with a producer/consumer queue but it would be simpler to either create a new thread or use the thread pool.

Jon Skeet