> On Mar 25, 2:18 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
> wrote:
[quoted text clipped - 32 lines]
>
> - Show quoted text -
Sorry, yes, it is System.Window.Window instead of Form.
> Thanks and it is a WPF project but my main class is derived from
> Window class. Based on what I understood, you are saying not to check
> for invoke required instead call the delegate with a method which will
> update the GUI always? Is it right?
Well, don't call the delegate directly. Do use Invoke() (or
BeginInvoke()). But yes, don't bother checking whether invoking is
required. If it's not, it's only slightly more overhead to do the invoke
anyway, and presumably this code is in a place where practically all the
time you'd need to invoke anyway.
Of course, all this assumes you're using a System.Windows.Forms control,
where calling Invoke() would be required. Seeing as you've said this is a
Window, not a Form, and that you're using WPF, the above advice may not be
applicable at all.
Note: I did a quick search, and found this article:
http://msdn2.microsoft.com/en-us/library/ms741870.aspx
If I read it correctly, it appears that WPF shares the same cross-thread
issues that exist for a Forms-based application, but address them in a
different way. Instead of there being an Invoke() method on the
individual controls, there's a Dispatcher object that you use to call
Invoke(). You can get this Dispatcher from the WPF object using the
Dispatcher property (inherited from the DispatcherObject class) of your
WPF controls (and maybe from the Window as well...I didn't look).
I note that in the Dispatcher class, there's no direct way to find out
whether the Dispatcher is for the current thread or not. It has a Thread
property, and you could compare that to the current Thread instance. But
that's a bit awkward. It appears they expect you to just call Invoke()
without checking to see whether doing so is required.
In other words, it looks like the folks who designed WPF agree with me on
the InvokeRequired property question. :)
Pete
CSharper - 25 Mar 2008 20:54 GMT
On Mar 25, 2:49 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > Thanks and it is a WPF project but my main class is derived from
> > Window class. Based on what I understood, you are saying not to check
[quoted text clipped - 32 lines]
>
> Pete
Thank you very much and I will read the information and yes, it make
sense to call the control without double function coding in a single
method.
CSharper - 25 Mar 2008 21:15 GMT
On Mar 25, 2:49 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > Thanks and it is a WPF project but my main class is derived from
> > Window class. Based on what I understood, you are saying not to check
[quoted text clipped - 32 lines]
>
> Pete
Excellent, it make perfect sense now. Thanks.