[Mono-winforms-list] Too slow performance on RichTextBox?

Andreia Gaita shana.ufie at gmail.com
Wed Mar 28 14:52:32 UTC 2012

On Tue, Mar 27, 2012 at 12:16, sharkal <wolfgang.ginner at kapsch.net> wrote:

> Hi,
> at the meantime i wrote a small test programm where it does the following:
>                while (indexCounter < maxIndexCount)
>                {
>                    var timestamp = (String.Format("{0:yyMMdd
> HH:mm:ss:fff}", DateTime.Now));
>                    rtxtOutput.AppendText(indexCounter + "  " + timestamp +
>                                                   " This is a output text
> to test the output time.\n");
>                    indexCounter++;
>                    Thread.Sleep(1);
>                }
> So the while loop do nothing more, than writing the actual  timestamp to
> the
> textbox, sleep 1ms and write the next text out.
> If i do this with mono, i have a time differents of ~ 15-20ms , in windows
> it is around 1-2ms.
> The Richtextbox is all with the default settings.
> Does anyone knows how to get a better performance here?
You're probably getting the 15ms time on the thread sleep because that is
(or was) the time it took to set it up and execute on windows,
traditionally. Since timings are sensitive, it wouldn't surprise me if our
implementation used slower codepaths or less precise timers to emulate this
behaviour (can't say for certain as I haven't looked at the code, but the
time is too close to be a coincidence).

Instead of using Thread.Sleep, which is not precise and can vary from to
system and from OS version to OS version (as you've noticed), use a wait
handle. The WaitOne (ms) overload of the WaitHandle uses precise timers so
it should give you much more accuracy and much less overhead, since it
doesn't have to mess with the thread. It can be interrupted if you want,
and it will return immediately with no blocking if the signal is set (or
you pass -1). For your scenario, just create a ManualResetEvent object with
false in the constructor (so it's not signaled), and then call WaitOne (1)
on it every time you want to wait.

andreia gaita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20120328/9fa0c128/attachment.html>

More information about the Mono-winforms-list mailing list