Re: When is Invoke() Really Required?
From: Sijin Joseph (sijindotnet_at_hotmail.com)
Date: 04/08/04
- Next message: JezB: "tABpAGE.eNABLED"
- Previous message: Ken Tucker [MVP]: "Re: NotifyIcon is empty when context menu is owner drawn"
- In reply to: Kenny Carruthers: "When is Invoke() Really Required?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 8 Apr 2004 17:08:19 +0530
Hi Kenny,
In my experience if your method does not touch any UI related operations
then it is safe to call that method. You see when you call a method it runs
in the context of the calling thread, now if the calling thread does not
have the message pump related infrastructure( For details refer to
Programming applications for windows by Jeffery Ritcher) then posting or
generating any messages from that thread won't work. Since ultimately even
.Net controls work using messaging the results will be unexpected. That any
method that might generate a message is a candidate for calling through
Invoke()
-- -Sijin Joseph http://weblogs.asp.net/sjoseph "Kenny Carruthers" <ken@kennyc.com> wrote in message news:O3cKpJPHEHA.2720@TK2MSFTNGP11.phx.gbl... > The documentation for InvokeRequired states that: > > --------------- > There are four methods on a control that are safe to call from any thread: > Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method > calls, you should use one of these invoke methods when calling from a > different thread. > --------------- > > Does this apply for absolutely every method or property in a control or > just those methods and properties that actually touch the UI? For example, > if I have a custom control derived from UserControl, can I call methods on > that custom control that don't touch any user interface elements from > another thread? What about for properties. > > Clearly I can't call things like SetText, ForeColor, etc... But it would > seem save to call something a method or property that just does some > internal calculation or am I wrong? > > On a related note, it would seem that from the description above, that I > can't call Invalidate() inside a method if that method was called from a > worker thread. But doesn't Invalidate() just post a WM_PAINT message to the > UI thread? Why do I have to go through Invoke() when calling Invalidate()? > > Thanks in advance for any help. > Kenny > >
- Next message: JezB: "tABpAGE.eNABLED"
- Previous message: Ken Tucker [MVP]: "Re: NotifyIcon is empty when context menu is owner drawn"
- In reply to: Kenny Carruthers: "When is Invoke() Really Required?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|