Re: invoking a method on a particular thread
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 21 Oct 2005 07:33:01 +0100
<gkellymail@xxxxxxxxx> wrote:
> In general what I would like to do is have an application with X number
> of threads and then be able to call a method and have it execute in the
> thread of my choice. What would be the best way to accomplish this?
All of the threads *have* to know that you want to do this, and have to
either poll a queue of "things to do" or actively wait on such a queue
(in the same way that the UI effectively waits on the message queue).
> One reason I want to do this is that I'm working on a asp.net
> application. This app will use an acitveX control that will generate
> map images for me. This activeX control also must run in a thread with
> appartment state STA. So, after this thread creates an instance of
> this activeX control I would like it to "sleep" and wait to be told
> what to do.
Right. That's basically a producer/consumer thread. See
http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml
half-way down the page. You'll need to pass an object which contains
all the information you need. In many ways, this would be like the
information stored for a custom threadpool work item - see
http://www.pobox.com/~skeet/csharp/miscutil
for the code to such a threadpool. (The threadpool itself might not be
useful to you, but the bit that takes the parameters and invokes the
method might. See MiscUtil.Threading.ThreadPoolWorkItem.)
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- invoking a method on a particular thread
- From: gkellymail
- invoking a method on a particular thread
- Prev by Date: invoking a method on a particular thread
- Next by Date: Re: Regex problem when spanning multiple lines
- Previous by thread: invoking a method on a particular thread
- Next by thread: Re: Regex problem when spanning multiple lines
- Index(es):
Relevant Pages
|