Re: Raising UI-level events from a thread without using Invoke?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 19 Feb 2007 12:25:25 +0800, Bruce Wood <brucewood@xxxxxxxxxx> wrote:
Most of the "classic" Invoke examples I've seen do this in order to re-
use the same routine as Invoked or not Invoked, viz: the routine
checks InvokeRequired and, if it's true, Invokes "itself", so the
second go around InvokeRequired will be false and the "else" part will
execute the actual machinery of the method.

That's true. But I don't see the advantage of keeping all the code in a single routine. Everyone can still call an invoking rotine, and the invoking routine can use a separate delegate method to do the actual work.

In fact, to my eye having a single method have two entirely different behaviors goes against my general coding principles. It's not terrible in this case, but it's not pretty either. :)

Of course, if you use two methods: a facade that calls Invoke and
another method that does the actual work, there's no real need to
check InvokeRequired in the first routine.

Exactly! :)

Pete
.



Relevant Pages