Re: Call Paint Event

CrashPilot

Newcomer
Joined
Apr 22, 2010
Re: Call Paint Event

I got an interesting one. For some reason the when i call the refresh method from a plugin construction it throws the crossthread error and the lot crashes. But when i call the invalidate method it actually works fine. Now i am realy interested why the invalidate method doesnt throw an exception. I mean, they both refresh the screen but one seems crossthreadable and the other not. Anyone know why that is?

(I do call the method from a thread in the plugin so the fact that the error is thrown is clear to me)

Greetings,

CrashPilot


edit: split from http://www.xtremedotnettalk.com/showthread.php?t=70168
 
Last edited by a moderator:

PlausiblyDamp

Administrator
Joined
Sep 4, 2002
Location
Lancashire, UK
Re: Call Paint Event

Without doing any real investigation I would imagine the .Refresh method is being run on the thread that actually calls the .Refresh, Invalidate on the other hand tells windows that you need to redraw yourself and it sends a message to the window in question - this will be picked up by the UI thread and therefore normal rules are being followed.
 

CrashPilot

Newcomer
Joined
Apr 22, 2010
Re: Call Paint Event

So what you are saying is that the invalidate is some sort of "invoke" of the redraw method and onpaint is called for that reason. That would make sense. Yet i also often note that if one would call the invalidate the picture / form isn't redrawn at all while refresh alway's works.

I must investigate, mouhahahaha (evil laugh)

p.s.

I didn't intend to have this post on a new thread but as a reply to an existing thread talking on this issue :S. Somehow that went wrong.
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
Re: Call Paint Event

p.s.

I didn't intend to have this post on a new thread but as a reply to an existing thread talking on this issue :S. Somehow that went wrong.
PD split your post from the thread because the thread was seven years old. You generally want to start a new thread with a link to the old thread if the thread is more than a month old or if your post is not answering or supplementing an answer to the original question.

As far as why invalidate works, it's not quite like your typical cross-thread call (.Invoke). It does cause code the be called on the UI thread, but only because it works through the message pump. That's just a happy accident I guess.

The reason Invalidate doesn't always cause a redraw is because Windows tries to optimize the invalidation/paint cycle. If you invalidate several rectangles in quick succession, Windows can combine them into a single paint event. (Notice, if your version of windows doesn't use desktop compositing, that when you drag window X over windows Y, window X moves for several frames, leaving path of blankness or artifacts in its wake, before window Y is redrawn.) This also means that Windows tends to "wait and see" when you invalidate. There can be a slight delay. When debugging (paused), the message pump is frozen and the Paint event might never be raised.
 
Top Bottom