Re: encapsulating invoking for thread communication
Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance
Glad to have helped.
thread will block. This would then nullify any advantage of using the
pool. Is this correct?
Not exactly. Yes the threadpool should not be used for long blocking
operations as you are "taking out" one of the threadpool threads, but 100ms
doesn't seem long to me (in a managed environment). In addition, the pool
limit on netcf v1.0 is 256 so there are plenty more where it came from!
For more on the thread pool (compared to desktop and netcf v2.0) see this:
http://www.danielmoth.com/Blog/2005/02/threadpool.html
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"James Salter" <jsalter@xxxxxxxxxxxxxxx> wrote in message
news:OpxeRjohFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
Thanks, this is the sort of pattern I was looking for.
Using my own ISynchronizeInvoke definition might be a bit hazardous as it
would force clients of the object to subclass a control to implement the
interface, but they're likely passing the main form which is subclassed
already anyway. And passing an interface is a more attractive solution to
the problem than a concrete class.
Reading those docs also piqued my interest in ThreadPool, but I am not
entirely confident I understand its operation. If I call Sleep(100) from
within a ThreadPool invoked callback, my understanding is that the pooled
thread will block. This would then nullify any advantage of using the
pool. Is this correct?
James
Daniel Moth wrote:
You've already mentioned the conventional solution. Allow the user to
provide the control that you Invoke on. In fact, you should check that
they have provided a reference and if they have not you should let the
event be raised on the worker thread (it is their decision).
See the interface exposed by System.Timers.Timer [not available on the
Compact Framework, but the principle applies] and in particular the
SynchronizingObject property.
Finally, since the System.ComponentModel.ISynchronizeInvoke is not
available on netcf, you could define that to keep some compatibility with
the full fx.
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"James Salter" <jsalter@xxxxxxxxxxxxxxx> wrote in message
news:ucKI1kghFHA.1052@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I have been using Control.Invoke() extensively on a project in order to
pass information from various worker threads to the interface thread.
Most of my worker objects hide this functionality by raising events that
are garuanteed to be fired in the constructing thread, by instantiating
a protected Control in the constructor and using it with Invoke later
on, to call delegates and then raise the events.
This is nice in the sense that it hides everything from the caller, and
is truly an encapsulated solution, but as I get more and more of these
worker threads I am starting to become concerned about the footprint of
these invisible Controls.
The alternatives to doing it this way are, get the caller to pass a
Control to the object (which might be inconvenient, and exposes the
internals somewhat), or maintain a static reference to the applications
main form somewhere. The latter solution is attractive, but i can't
figure out how to implement it without the client having to set the main
form themselves, which seems like a bad way of doing things.
What is the general convention for solving this problem?
James
.
Relevant Pages
- Re: encapsulating invoking for thread communication
... if you need a thread dedicated for a single task you should explicitly use a thread. ... the pool limit on netcf v1.0 is 256 so there are plenty more where it ... provide the control that you Invoke on. ... pass information from various worker threads to the interface thread. ... (microsoft.public.dotnet.framework.compactframework) - Re: encapsulating invoking for thread communication
... I should have stated that i was going to have the thread spin in a loop with the sleepinside the loop. ... provide the control that you Invoke on. ... pass information from various worker threads to the interface thread. ... (microsoft.public.dotnet.framework.compactframework) - Determining that the Application want to quit from within a thread
... My scenario ws that I had a small group of worker threads ... called and the delegate invoked does some updating on the control. ... terminate the application, ... While the Application object has an OnExit event there does not ... (microsoft.public.dotnet.framework) - Re: Boston Tournaments: March 15th Multi-deck and April 5th Custom Storyline
... may pay 1 pool or use a master phase action to take control of the Abyssal ... Nightmare during their minion phase. ... "Any Methuselah who controls a ready minion during their master phase ... (rec.games.trading-cards.jyhad) - Re: Random ALL ON Signals
... My first guess might be "check with the neighbors". ... The guys across the street had just had a pool installed, and their pool contractor had given them a "remote control". ... The guys across the street has no clue on what x10 was, only that they had a remote for their pool. ... (comp.home.automation) |
|