Re: invoking a method on a particular thread

Tech-Archive recommends: Fix windows errors by optimizing your registry



<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
.



Relevant Pages

  • invoking a method on a particular thread
    ... of threads and then be able to call a method and have it execute in the ... appartment state STA. ... this activeX control I would like it to "sleep" and wait to be told ...
    (microsoft.public.dotnet.framework)
  • Re: East India Company has open beta
    ... "Peter Huebner" wrote in message ... could not install the activeX control and then gave me a link to ... proceed to the queue which opened a javascript window that ticked down ...
    (comp.sys.ibm.pc.games.strategic)
  • Re: Single producer, "one-shot" work queue implementation, no lock on queue.
    ... usec for just calling execute() directly). ... overhead that's closer to 5nsec than 5usec. ... where there's only a single item in the queue. ... virtual void Execute() = 0; ...
    (comp.programming.threads)
  • Re: Do I need a RTOS?
    ... place, everything is empty ... ... the queue and requesting that I always keep some task in the queue. ... It is there that I call the execute function, over and over, pumping ... timer event, of course. ...
    (comp.arch.embedded)
  • Re: VB6 (formless) Timer class
    ... What you need to be concerned about is the thread used to execute ... other processing in your application grinds to a halt until that routine has ended. ... That includes the code you want responding to incoming calls. ... If the 'queue' response is acceptable to you, why not build it as a queue, ...
    (microsoft.public.vb.general.discussion)