|
sasabunetic wrote: How should I solve this problem?
You will have to use the native multimedia timer. Look on PInvoke.net or Google how to use that.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Thanks for this.
You've helped me alot
|
|
|
|
|
|
None of them have a resolution of less than 10-15 milliseconds.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Thanks, I didn't know it
|
|
|
|
|
AFAIK, DateTime.Now.Ticks has 100ns intervals. You may give it a try...
Regards,
Always keep the Murphy Rules in mind!
|
|
|
|
|
Not an answer.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
http://cplus.about.com/od/howtodothingsinc/a/timing.htm
Stopwatch st=new Stopwatch();
st.Start();
Console.WriteLine("Started");
for (ulong i2 = 0; i2 < 10000000; i2++)
{
ulong ul2 = i2;
ul2++;
}
st.Stop();
Console.WriteLine("Elapsed = {0}", st.Elapsed.ToString());
if (Stopwatch.IsHighResolution)
Console.WriteLine("Timed with Hi res");
else
Console.WriteLine("Not Timed with Hi res");
Enjoy
|
|
|
|
|
Not what the OP asked. He wants a timer, not timing.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
He wanted accurate timing. Timer and timing - what's the difference?
Do enlighten me
|
|
|
|
|
A timer fire periodically, a timing measures the time something takes.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
|
Couldn't agree more
|
|
|
|
|
Luc... you're our only hope.
|
|
|
|
|
Now I beg to differ.
|
|
|
|
|
Hi, I want to use the javascript function in c#.net window application. Is it possible? If yes, then how?
|
|
|
|
|
|
I'm currently writing a custom control for use with a WinForms application - basically, it's a hex editor control, which displays offsets, rows of bytes, a text column, and some other information.
I'm doing all the drawing inside OnPaint, but I've started to notice that rendering becomes a little laggy when the control is large (and thus a lot of bytes are being drawn). In extreme cases it can take around 20 to 30 milliseconds to draw the entire control. This isn't terrible, but it makes dragging selections feel very slightly sluggish, and I'm sure it's much worse on lower-end machines.
The control is entirely text based - aside from a couple Graphics.DrawPath/FillPath calls, the bulk of the GDI+ calls are to Graphics.DrawString (one for each byte displayed, to allow for custom column spacing). These DrawString calls end up taking up the vast majority of the rendering time.
Is there any faster way to do text drawing in GDI+? It seems that it would be a good move to try to reduce the number of DrawString calls, but how can I do that while still maintaining control over the spacing of characters?
Perhaps there's another, simpler way of rendering text for this purpose that I'm just unaware of? Any advice would be appreciated.
|
|
|
|
|
Check the clipping of the graphics object that you get in the Paint event. It should be clipped to the area that needs redrawing, and if that area is smaller than the control, you only have to draw the cells needed to cover that area.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I did try only invalidating the regions that need to be redrawn, and it helped a bit, but not a whole lot. I guess I'll try also only computing and calling DrawString for the invalid cells too; thanks for the suggestion.
|
|
|
|
|
It is a hard art to master, but text can be drawn very fast under GDI+. There is just too much detail to go into, but you can look at my 'AdvancedTextBox' control in xacc.ide. The source code is on sourceforge.
To summarize:
- Tokenize data
- Optimize tokens by grouping similar ones (store this and 'invalidate' if the 'line/text' changes)
- Paint the groupings
I would also suggest sticking to monospace fonts. Then only 1 call is needed to get the width of a character.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
So, basically you're talking about ways to reduce the number of DrawString() calls, right? Tokenizing isn't a problem since it's just a series of bytes; some sections can be rendered differently because of selection or other highlighting, but this wouldn't be hard to keep track of.
This still leaves me with the problem of maintaining a precise layout, though. If I draw the text in this fashion, I'm limited by the default spacing (both space character width and line height) of the font, which often puts columns and lines way too far apart to be visually pleasing in a hex editor. Is there some method of controlling the way GDI performs text metrics?
|
|
|
|
|
Mr. Accident wrote: In extreme cases it can take around 20 to 30 milliseconds to draw the entire control.
To add: Only paint what you see, there is no need to paint the invisible parts of the control.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Also, avoid creating new objects (pens, brushes, fonts, ...) in your Paint handler.
What I typically do is have some class members to hold those, inside the Paint handler null-check them
and create new objects if necessary, and everywhere else set them back to null when they will have
to be replaced.
And lastly, whatever disposable object you create, don't forget to call Dispose() on it when
you no longer need it.
The net result is painting does not cause unnecessary GC activity.
|
|
|
|
|
...programatically?
many thanks!
----------------------------------------------------------
"unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix command list
|
|
|
|