Worker Thread

G

Guest

Hello there,
Just a few questions re: worker theads.

I have a worker thread that i wish to perform certain task.
This worker thread must also handle events.

Now my real questions.....

What sort of ipc will i use between threads? (i used PostThreadMessage on
win32)
What sort of run loop should my thread have?

thanks in advance
Brian Keating
 
G

Guest

I'm not sure if this will be exactly what you need, but my experience is that
the only way to communicate between .NET threads is if the thread that
receives the messages is in the traditional Windows Form messaging loop. If
it is, then you can execute a method on the recipient's thread by using the
Control.Invoke method, the caveat being that the control used in the Invoke
needs to have as its parent the form associated with that loop.

Hope this helps.
 
J

Jon Skeet [C# MVP]

<"=?Utf-8?B?QnJ1Y2UgSm9obnNvbiBbQyMgTVZQXQ==?=" <Bruce Johnson [C#
MVP]@discussions.microsoft.com> said:
I'm not sure if this will be exactly what you need, but my experience is that
the only way to communicate between .NET threads is if the thread that
receives the messages is in the traditional Windows Form messaging loop. If
it is, then you can execute a method on the recipient's thread by using the
Control.Invoke method, the caveat being that the control used in the Invoke
needs to have as its parent the form associated with that loop.

No, you can write your own kind of messaging loop perfectly easily. See
the producer/consumer queue in
http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml (half way
down) for an example.
 
G

Guest

Thanks Bruce for your reply

Bruce Johnson said:
I'm not sure if this will be exactly what you need, but my experience is that
the only way to communicate between .NET threads is if the thread that
receives the messages is in the traditional Windows Form messaging loop. If
it is, then you can execute a method on the recipient's thread by using the
Control.Invoke method, the caveat being that the control used in the Invoke
needs to have as its parent the form associated with that loop.

Hope this helps.
 
G

Guest

Yes thanks again Jon,

I could do something along these lines with delegates for the functions i
wish to execute and some member variables, i'd prob need an extra level of
locking so that two threads couldn't try set the consumer state (i.e.
delegate and variables it will call with) before the consumer gets woken up.

Thanks alot
Brian.

Jon Skeet said:
<"=?Utf-8?B?QnJ1Y2UgSm9obnNvbiBbQyMgTVZQXQ==?=" <Bruce Johnson [C#
MVP]@discussions.microsoft.com> said:
I'm not sure if this will be exactly what you need, but my experience is that
the only way to communicate between .NET threads is if the thread that
receives the messages is in the traditional Windows Form messaging loop. If
it is, then you can execute a method on the recipient's thread by using the
Control.Invoke method, the caveat being that the control used in the Invoke
needs to have as its parent the form associated with that loop.

No, you can write your own kind of messaging loop perfectly easily. See
the producer/consumer queue in
http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml (half way
down) for an example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top