[.net] .NET message loop

Started by
15 comments, last by a2ps 18 years, 7 months ago
We had a developer from Microsoft lecture at our school about game programming in C#, and he said that the OnPaint should be used.
Advertisement
From memory the OnApplicationIdle was compared (by Tom Miller) against the other methods and turned out to be the best solution. IIRC it's in his last blog entry on the managed render loop.

In the idle event you call PeekMessage and loop until there is a message waiting, then return and let it be handled by System.Windows.Forms.Application.Run()'s event loop, then your idle event will be called again once the messages have been processed.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
I've used both the while loop with Application.DoEvents() and a Timer, with both giving pretty much comparable results. I prefer the syntax of the Timer, so I will stick to it.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.
------Tech, life, family, faith: Give me a visit.
Quote:Original post by Swamii
Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.

excellent find. by my rough calculations from hacking this into some existing code, this is at least 20% faster than using a Timer or a while loop with Application.DoEvents. The timer and app.doevents are roughly equivalent.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Quote:Original post by Swamii
Check out the Managed DirectX 9 creator's latest post on render loops: clickity. Hint: Invalidate and DoEvents both have a lot of overhead, affecting both memory and performance.


Feels like a hack, what's the point of using .NET if you still have to use win32 functions...
you can use only managed methods if you want, you just wont have as good performance (as the win32 loop is concerned) as using native methods.

the DoEvents() and OnPaint() methods just do too many memory allocations/deallocations, and thats something you dont want in a game (where performance is too important).
yet, another stupid signature..

This topic is closed to new replies.

Advertisement