Re: EndInvoke still required?
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 08 Jan 2008 14:58:37 -0800
On Tue, 08 Jan 2008 14:31:44 -0800, Erik Funkenbusch <erik@xxxxxxxxxxxxxxxxxxxxxx> wrote:
[...]This would be true most of the time, but at some point you're going to
have the last receive callback that occurs. This will presumably call
BeginInvoke() still, and there will never be another receive callback to
provide the opportunity to call EndInvoke().
Yes, I would obviously have to deal with this situation in some application
cleanup code. However, since the application would be ending anyways, i'm
not sure it's that important to clean up, other than for neatnesses sake.
Well, it depends on the resources being used. It does seem like in the case of Control.BeginInvoke(), no resources that have external effects would be involved and that just ignoring the cleanup would be fine.
Of course, since we've already seen reasonably good information suggesting cleaning up is unnecessary in any case, it seems odd to be even talking about under what _other_ situation cleanup might or might not be optional.
Other solutions would be similar, involving a queue processed somewhere.
You could put a timer on the Form, or run a dedicated consumer thread.
These should all be able to process _all_ of the EndInvokes() necessary.
The timer would just use unnecessary resources, running when it didn't have
to. And creating a consumer thread for this one purpose seems wasteful as
well.
Even more convoluted, you could use the Delegate async methods
BeginInvoke() and EndInvoke(), which _do_ provide a callback (so you can
easily clean those up). You could use the asynchronously invoked delegate
either to call Control.EndInvoke(), or even just to call Control.Invoke()
directly (avoiding the entire Control.Begin/EndInvoke() issue altogether
:) ).
This is a good solution actually. I see it as less convoluted and less
resource wasteful (since the delegate async threads will come from the app
worker thread pool).
I don't see this as any less wasteful than using a timer or another thread. The timer in particular should be reasonably low impact, since it takes advantage of the built-in WM_TIMER mechanism. You don't even need a new thread to service the timer, and your GUI thread needs to be processing events every now and then anyway. A single extra consumer thread isn't really that big of a deal, and it's not like queuing something on the thread pool is completely cost-free (also, using the thread pool exposes your code to congestion in the thread pool, something that Control.BeginInvoke() wouldn't otherwise have to worry about).
In other words, I don't think any of the solutions are _especially_ wasteful, and I don't see using the thread pool via Delegate-async mechanisms is obviously better, even though I think that all of the possibly solutions are probably pointless. :)
It could be packed up into a helper class, quite
easily and far less prone to maintenance errors. But, as you say, still
more work than is strictly necessary if Control.EndInvoke is guaranteed to
not be needed.
Exactly.
Pete
.
- Follow-Ups:
- Re: EndInvoke still required?
- From: Erik Funkenbusch
- Re: EndInvoke still required?
- References:
- EndInvoke still required?
- From: Erik Funkenbusch
- Re: EndInvoke still required?
- From: Michael Nemtsev [MVP]
- Re: EndInvoke still required?
- From: Erik Funkenbusch
- Re: EndInvoke still required?
- From: Peter Duniho
- Re: EndInvoke still required?
- From: Erik Funkenbusch
- Re: EndInvoke still required?
- From: Peter Duniho
- Re: EndInvoke still required?
- From: Erik Funkenbusch
- EndInvoke still required?
- Prev by Date: Re: EndInvoke still required?
- Next by Date: how to search tfs by name of file or contents in file?
- Previous by thread: Re: EndInvoke still required?
- Next by thread: Re: EndInvoke still required?
- Index(es):
Relevant Pages
|