Timer not invalidating

Rated 4.59/5 based on 827 customer reviews

Opaque, true); And the entry point to this program is like so: static void Main() I have my onpaint function call Invalidate at the very end like so: protected override void On Paint(System. I'm soooo close to the solution that I can almost taste it, but I'm stuck. Invoke", but they were not clear on how it would apply to my particular situation...) Thanks in Advance, -alex- Hi, I have a simple form that handles all its paint functionality like so: this. Seems to me you've got a pretty classic infinite loop there. Of course, if your timer code has to interact with the window, you will wind up having to use Invoke or Begin Invoke, which introduces a dependency on the message queue again. IMHO, however, you should rethink the wisdom of calling Invalidate from within your On Paint handler. Generally speaking, you should only ever call Invalidate when there has actually been some change in the data being drawn.

Paint Event Args e) The problem is that I want to setup a System. In my own ignorance, I thought that when you create a timer it creates a new thread, independent of the message loop of the application, but apparently not. Invoke somewhere, and/or possibly modifying Main so that when i create a Timer it can operate independently of the On Paint loop. (I've looked at various topics in google, and they too point to "Control. Opaque, true); And the entry point to this program is like so: static void Main() I have my onpaint function call Invalidate at the very end like so: protected override void On Paint(System. I'm soooo close to the solution that I can almost taste it, but I'm stuck. Invoke", but they were not clear on how it would apply to my particular situation...) Thanks in Advance, -alex- Let me make sure I understand what you are saying: In your overridden "On Paint" handler, which is called in response to a paint event, which occurs any time an area of the control (form) is invalidated, you invalidate the entire control (form)? In my own ignorance, I thought that when you create a timer it creates a new thread, independent of the message loop of the application, but apparently not. If you want a timer that operates independently of the message queue, you should probably use something like Threading. That will use a different thread to handle the timer.

For example, my On Paint function is currently doing way too much work: For instance, the game lags significantly when a monster is performing a "Shortest Path Algorithm" call on a target that is very far away, and it's because that function call is inside On Paint. -alex- On Nov 27, pm, "Peter Duniho" In your overridden "On Paint" handler, which is called in response to a paint event, which occurs any time an area of the control (form) is invalidated, you invalidate the entire control (form)? Of course, if your timer code has to interact with the window, you will wind up having to use Invoke or Begin Invoke, which introduces a dependency on the message queue again. IMHO, however, you should rethink the wisdom of calling Invalidate from within your On Paint handler. Generally speaking, you should only ever call Invalidate when there has actually been some change in the data being drawn.

Seems to me you've got a pretty classic infinite loop there. It makes no sense to call Invalidate when what you've just done is to have redrawn the control.

It is theoretically possible to inspect the clipping area in the On Paint method, and not draw stuff that's entirely outside the clipped area.

But the biggest gains comes simply from the clipping itself; unless you have very simple, fast ways to avoid drawing altogether, it's faster to just run through all of the drawing code normally, and let Windows save you the time of actually drawing anything when it's outside the clipped area).

You may or may not need to introduce a new thread into your program. However, personally I would first attempt to solve your problem simply by removing the Invalidate from the On Paint handler. There are so many topics on the "ultimate c# game loop", but "they" say the easiest way to have a high frame rate game is to call Invalidate at the end of On Paint (for instance, but you are right; I'm flooding the message cue with On Paint which is why my poor timer never gets the message.

Going through User (the window message pump) and GDI (the invalidation/redraw paradigm) is overhead that isn't acceptable when frame rate needs to be maximized.You wouldn't waste time invalidating and waiting for a WM_PAINT message (which is what underlies the . In this case, often only small areas of the screen are actually going to change at any given time.Even if you have (for example) a grid playfield in which every other square contains an animated icon, a) only half the window actually needs to be redrawn, and b) it's unlikely you actually have icon animations rendered at as high a frame rate as is typically possible (for example, animations may be stored at 15 or 30 frames per second, while the actual possible frame rate might be over 100 fps, especially for 2D stuff..means most of the time, even the animated parts of your screen aren't changing from one frame to the next).In addition, for many games the worst thing you can do with respect to frame rate is to invalidate the entire window.Doing so (or the equivalent) makes a lot of sense for 3D games where the camera is always in motion, because the entire view is going to have to be redrawn every frame anyway. But if you don't have a 3D game, you're dealing with some sort of 2D sprite-like graphics, most likely.

Leave a Reply