Gilbert,
Here's an example.
public class Program
{
public static void Main()
{
// Get RunMessageLoop going in another thread.
}
private void RunMessageLoop()
{
Application.AddMessageFilter(new MyMessageFilter());
Application.Run();
}
private class MyMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == /* whatever */)
{
// Intercept and handle accordingly.
return true;
}
// Allow the message loop to dispatch the message.
return false;
}
}
}
Brian
[quoted text, click to view] gilbert@gmail wrote:
> Thank you very much for your tips. After searching from the web, I
> still have no idea how to use the message loop created by the
> Application.Run(). Like, how to put the custom message handler? How to
> post custom messages to the loop? I think it is the thing I am looking
> for, just I still have no idea how to use it!
>
> Any help would be greatly appreciated!
> Thanks!
>
> Gilbert
>
> Brian Gideon wrote:
> > Gilbert,
> >
> > You can call Application.Run to install a windows message loop on the
> > current thread. The PostThreadMessage or Control.BeginInvoke (if you
> > have a control hosted on the thread) can be used to dispatch messages
> > to the queue.
> >
> > If you don't want the message queue to receive windows messages then
> > you'll have to write your own.
> >
> > Brian
> >
[quoted text, click to view] Bruce Wood wrote:
> gilbert@gmail wrote:
> > Thank you very much for all of these tips. I think the MessageQueue
> > class is for messaging with MSMQ? I would try to check out the
> > Application.Run() method. I hope it is not an overkill as I just wanna
> > send some strings to some specific threads. I am trying to implement
> > the ActiveObject such that messages passing between threads are queued
> > up. The calling thread and called thread are decoupled where the
> > calling thread need not to know the status of the called thread. Thank
> > you very much for your helps!
>
> Have you seen Jon Skeet's excellent writeup on threading? I believe
> that he has an example of writing your own queue in there:
>
>
http://www.yoda.arachsys.com/csharp/threads/
Yep, jump to chapter 4 and look for the ProducerConsumer class. Jon,
have you considered changing your page so that the name of the class is
BlockingQueue instead? It would use Enqueue and Dequeue method names
instead of Produce and Consume. Though, Java's BlockingQueue uses put
and take as method names. The BlockingQueue nomenclature just seems to
be more..."academic" :)
Brian
[quoted text, click to view] Brian Gideon <briangideon@yahoo.com> wrote:
> Yep, jump to chapter 4 and look for the ProducerConsumer class. Jon,
> have you considered changing your page so that the name of the class is
> BlockingQueue instead? It would use Enqueue and Dequeue method names
> instead of Produce and Consume. Though, Java's BlockingQueue uses put
> and take as method names. The BlockingQueue nomenclature just seems to
> be more..."academic" :)
I'll add it to the wishlist and think about it some more. I think
having the methods called "Produce" and "Consume" make it more obvious
why the general pattern is called a producer-consumer...
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet