views:

1098

answers:

4

Hi all,

I have a problem drawing something quickly in .NET. I don't think that any thing in particular should take much time, but on every machine I've tried it on, I get serious issues. This is implemented in vs2008 .NET, using C# (with some stuff in C++, but nothing relevant to the drawing).

I have three screens, and the user should be able to toggle between them with no lag. On the first screen, there are four buttons, eight user controls consisting of two buttons and 6 labels each, a text field, and a dropdown box. I don't think of it as being that much.

On the second screen, I have four labels, six buttons, and two controls that have six buttons, one opengl drawing context, and about ten labels each.

On the third screen, I have one opengl context and 10 buttons.

Flipping from any screen to any screen takes literally about a second. For instance, if I flip from the second screen to the first, the entire application blanks out, showing the background screen, and then the first screen is drawn. Many times, a screen is drawn piecemeal, as if the machine were deliberately handcrafting delicate and delicious letters in a factory in Sweden and then shipping each one individually to my screen. I exaggerate, and I want to make that clear, because I don't think Swedes are as slow as this redraw.

The first and second screen are drawn in memory, and stored there, with just a '.Hide()' and '.Show()' to make them appear and disappear. Double buffering doesn't seem to matter. The third screen is drawn anew each time, and appears to take the same amount of time to draw as the first and second.

Any thoughts? What could be going on? How can I track it down?

Thanks!

Edit: I should add that any C++ processing and the like happens in its own thread. There is the occasional MethodInvoke to draw the results of the operation to the screen, but this problem happens without calling any functions, just by pressing buttons to go from one screen to the next.

A: 

Are you doing any other processing during the "screen flip" event? other than just letting the form be redrawn? If you are processing something between flips (maybe your c++ addition?), and you are not multi-threading, you get that white out effect. The form is probably waiting for CPU time to redraw itself.

scottm
That processing is user started; if the user doesn't start it, the problem still happens.
mmr
Can you run a profiler on your code?
Mitch Wheat
nope. Dottrace crashes whenever it starts, which is very frustrating. To say the least.
mmr
Have you tried other profilers...ANTS Profiler is supposed to be very good
Michael Prewecki
+1  A: 

In addition to the profiler that was mentioned, you might also turn off your OpenGL contexts. If you notice a speed-up, then you'll know it's your graphics stuff, and you can focus your optimisations accordingly.

Points awarded for Swedish humour.

Charlie Salts
The opengl stuff turned out to be, by far, the biggest time hog-- 80 ms per context per redraw, once I got dotTrace figured out.
mmr
+1  A: 

How can I track it down?

dotTrace - http://www.jetbrains.com/profiler/

Sean
for some reason, dotTrace is actually breaking my app when I try to run it. I can debug fine, but running dotTrace breaks the app immediately.
mmr
You might also try the System.Diagnostics.Stopwatch class. It's very simple to use, and is good for profiling specific pieces of code without the use of any add-ons or 3rd party applications.
Charlie Salts
With dotTrace, try both "Tracing profiling" and "Sampling profiling". With my application, I have better luck with "Sampling profiling", but it is a little less accurate.
Sean
I figured out what the problem was starting dotTrace-- the default startup directory wasn't the application's local directory, and that was causing the language packs to mess up.
mmr
A: 

I have never used OpenGL in such a way myself, but you might want to look at the way in that the OpenGL contexts are flipped. When switching from one page to another you might be getting a device reset (in DirectX terms), which could be causing the delay.

If at all possible have a device draw to a back System.Drawing.Bitmap, and use that bitmap on the screens. Make your OpenGL code aware of the current page the user is on, and you might get the speed up you seek.

To test this before making huge changes, try removing the OpenGL displays on your form.

This is all a whim.

Jonathan C Dickinson