473,466 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Time Critical Process in .NET

Hi guys

I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in a
specific time frame. The time when the process starts is not especially
important, but it must be complete within a small number of seconds.

The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker thread
raises an event that is handled by the UI thread, to update a rich text
control with details of the completed operation. I am using a rich text box
so that when a failure occurs I can colour the message red.

The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms. When this happens, the complete process overruns my time
frame, and it has to be repeated. When I repeat the process there is every
chance that it completes in a realistic time, and all is well. If I stop
outputting to the screen, I do not get the problem.

When updating the screen on the UI thread, I use BeginInvoke, to marshal the
operation to the correct thread, and so as not to hold up the worker thread,
but this does not seem to help.

I realise that Windows (XP in this case) is not the ideal o/s for this type
of application, but does anyone have any ideas about how I could make my
application more deterministic? I am not certain what is going on in these
2.5 seconds, so it might be useful if I could find out, but I am not sure
how I would do that.

TIA

Charles
Nov 22 '05
83 3021
Hi John

Thanks for the thoughts. I won't get chance to run PerfMon again until
Thursday (I have to go on site to do it), but I'll come back then. You have
got me thinking about the string thing though. The rich text box has an
Append type of method, but I don't know what it does internally. It might be
quicker to maintain the string outside the control with a string builder and
write it to the control fresh every time. The problem with that though is
the colouring of parts of the text. Hmm ... I'll have to give this some more
thought.

Cheers.

Charles
"JohnR" <Jo***@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Charles,

Before you start changing your messaging architecture, I would be
interested
in what you saw in Performance Monitor (discussed earlier). I have
definitely seen some latency in the past that I attributed to garbage
collection in .NET, although not in the magnitude you describe. Just how
much data are you allocating / de-allocating in your computation process?

Also, does your thread catch exceptions on a regular basis? I have seen
some very noticeable execution lag I had attributed to catching
exceptions,
but I was working on a simple UI at the time and did not investigate it.

Finally, I have not used an RTF control in .NET yet, does it work by
assigning a string? I.e.:

rtfThing.Text += sNewLine;

If so, and you have a lot of updates, this would certainly be a likely
culprit. The .NET string type is immutable, so the entire previous value
of
the string is copied to the new string every time you make a change.

Hope this helps... keep us updated.
"CMM" wrote:
You're probably right. But, I would think that a simple thread Timer
(rather
than a loop) in the UI is efficient enough to not steal CPU time from the
worker thread... and it might (or not) be more efficient than the event
model
/ begininvoke he is using.

"Jay B. Harlow [MVP - Outlook]" wrote:
> CMM,
> Causing the UI thread to periodically check the status means that it
> would
> need to use CPU time that the critical thread may need, I would think
> Charles would want to minimize the amount of work other threads are
> using...
>
> Using BeginInvoke means the UI thread will only update the status when
> the
> critical thread made a change...
>
> Just a thought
> Jay
>


Nov 22 '05 #51
I can't remember where I got up to with this thread, so this is a general
update on the problem.

I ran the application again this morning, against the real equipment. The
time critical parts of the process now seem to be more stable, after
implementing some of the suggestions, but at the severe detriment to the UI.
As mentioned before, the background process raises events when it wants to
notify the UI that something has happened, and the event handler marshals
the event onto the UI thread, using a delegate and BeginInvoke, and appends
the message to a rich text box.

The problem is now that the screen appears to be updating at a reasonable
pace, but it is clearly lagging a long way behind the messages being
supplied to it. At its worst, the background process finished, and it took
over five minutes for the screen to catch up. FIVE MINUTES! I think I have
got my pattern wrong here. I don't mind the screen lagging slightly behind,
but five minutes is just silly.

Going back to basics, I want to (need to) capture the messages passed in all
the events that the background thread raises, and I want to maintain a
display of these messages. Some messages will be coloured red to make them
stand out to the user, which is why I have used a rich text box.

Is there a better pattern for this type of application?

Incidentally, I ran this on a 3.0 GHz P4 Dell laptop, not the slower
Celeron m/c, so it will be much worse on the intended target m/c.

Charles
"Charles Law" <bl***@nowhere.com> wrote in message
news:uu***************@TK2MSFTNGP12.phx.gbl...
Hi guys

I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in a
specific time frame. The time when the process starts is not especially
important, but it must be complete within a small number of seconds.

The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker
thread raises an event that is handled by the UI thread, to update a rich
text control with details of the completed operation. I am using a rich
text box so that when a failure occurs I can colour the message red.

The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms. When this happens, the complete process overruns my time
frame, and it has to be repeated. When I repeat the process there is every
chance that it completes in a realistic time, and all is well. If I stop
outputting to the screen, I do not get the problem.

When updating the screen on the UI thread, I use BeginInvoke, to marshal
the operation to the correct thread, and so as not to hold up the worker
thread, but this does not seem to help.

I realise that Windows (XP in this case) is not the ideal o/s for this
type of application, but does anyone have any ideas about how I could make
my application more deterministic? I am not certain what is going on in
these 2.5 seconds, so it might be useful if I could find out, but I am not
sure how I would do that.

TIA

Charles

Nov 22 '05 #52
Charles,
What was the extent of your changes? What exactly were your changes? Can you
apply an individual change at a time to isolate which one is causing the
problem.

Can you use CLR Profiler or another profiler to isolate *exactly* where the
slow down is? As other wise we are all just guessing as to where the problem
lies!

I saw a question the other day that I though might apply here. Is the slow
down occurring on the first Exception that occurs in your app? Remember for
apps that run under the debugger, the first exception usually takes about 2
seconds...

Is the JIT compiler loading & compiling code that causes the slow down?
want to maintain a display of these messages. Some messages will be
coloured red to make them stand out to the user, which is why I have used
a rich text box.
Have you considered an Owner Draw ListBox, a ListView or other control, that
is a little more "light weight" then a RichTextBox?

For example ListViewItem has a ForeColor property on it...

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...I can't remember where I got up to with this thread, so this is a general
update on the problem.

I ran the application again this morning, against the real equipment. The
time critical parts of the process now seem to be more stable, after
implementing some of the suggestions, but at the severe detriment to the
UI. As mentioned before, the background process raises events when it
wants to notify the UI that something has happened, and the event handler
marshals the event onto the UI thread, using a delegate and BeginInvoke,
and appends the message to a rich text box.

The problem is now that the screen appears to be updating at a reasonable
pace, but it is clearly lagging a long way behind the messages being
supplied to it. At its worst, the background process finished, and it took
over five minutes for the screen to catch up. FIVE MINUTES! I think I have
got my pattern wrong here. I don't mind the screen lagging slightly
behind, but five minutes is just silly.

Going back to basics, I want to (need to) capture the messages passed in
all the events that the background thread raises, and I want to maintain a
display of these messages. Some messages will be coloured red to make them
stand out to the user, which is why I have used a rich text box.

Is there a better pattern for this type of application?

Incidentally, I ran this on a 3.0 GHz P4 Dell laptop, not the slower
Celeron m/c, so it will be much worse on the intended target m/c.

Charles
"Charles Law" <bl***@nowhere.com> wrote in message
news:uu***************@TK2MSFTNGP12.phx.gbl...
Hi guys

I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in
a specific time frame. The time when the process starts is not especially
important, but it must be complete within a small number of seconds.

The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker
thread raises an event that is handled by the UI thread, to update a rich
text control with details of the completed operation. I am using a rich
text box so that when a failure occurs I can colour the message red.

The problem I have is that sometimes, for no apparent reason, a step in
my process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms. When this happens, the complete process overruns my time
frame, and it has to be repeated. When I repeat the process there is
every chance that it completes in a realistic time, and all is well. If I
stop outputting to the screen, I do not get the problem.

When updating the screen on the UI thread, I use BeginInvoke, to marshal
the operation to the correct thread, and so as not to hold up the worker
thread, but this does not seem to help.

I realise that Windows (XP in this case) is not the ideal o/s for this
type of application, but does anyone have any ideas about how I could
make my application more deterministic? I am not certain what is going on
in these 2.5 seconds, so it might be useful if I could find out, but I am
not sure how I would do that.

TIA

Charles


Nov 22 '05 #53
Hi Jay

One of the changes I made was to stop exceptions being raised for events
that could occur as a normal part of the background process. I was throwing
an exception to indicate a process step failure, whereas I now always return
a Result class that indicates the state. That said, these failures did not
occur very often and, all being well, won't happen at all, but it is now
neater this way.

I also raised the priority of the worker thread to Highest.

I haven't got to grips with the CLR Profiler yet; perhaps I should :-)
Intuitively, I feel that the problem is that the worker thread is now taking
all the time it needs, and the UI thread is getting only a small amount of
time. If the worker thread is performing its tasks at full tilt it will
raise an event every 50 ms or so, with longer gaps here and there. I just
don't think that the UI can keep up. Messages appear on-screen at a goodly
rate, but as the rich text box gets fuller it appears to get slower. When
the whole process was over I saved the contents of the rich text box and
opened it in word. The file is 2 Mb long, and converts to 319 A4 pages.

As far as applying a change at a time, I am somewhat hampered by access to
equipment, and although I can test fairly well off-site, I don't get the
same problems because I can only execute a small number of the processes
properly.
Have you considered an Owner Draw ListBox, a ListView or other control,
that is a little more "light weight" then a RichTextBox?
I did think about this but thought that it would actually be slower. I
thought that as the rich text box is free text it should be quicker to tack
stuff on the end, whereas I imagine that the listview will create an object
for each line and would therefore take longer and be more memory hungry. Now
you suggest it though I think I will try it. In fact, if it is quicker it
will probably make the management and navigation of the information easier.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Charles,
What was the extent of your changes? What exactly were your changes? Can
you apply an individual change at a time to isolate which one is causing
the problem.

Can you use CLR Profiler or another profiler to isolate *exactly* where
the slow down is? As other wise we are all just guessing as to where the
problem lies!

I saw a question the other day that I though might apply here. Is the slow
down occurring on the first Exception that occurs in your app? Remember
for apps that run under the debugger, the first exception usually takes
about 2 seconds...

Is the JIT compiler loading & compiling code that causes the slow down?
want to maintain a display of these messages. Some messages will be
coloured red to make them stand out to the user, which is why I have used
a rich text box.


Have you considered an Owner Draw ListBox, a ListView or other control,
that is a little more "light weight" then a RichTextBox?

For example ListViewItem has a ForeColor property on it...

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I can't remember where I got up to with this thread, so this is a general
update on the problem.

I ran the application again this morning, against the real equipment. The
time critical parts of the process now seem to be more stable, after
implementing some of the suggestions, but at the severe detriment to the
UI. As mentioned before, the background process raises events when it
wants to notify the UI that something has happened, and the event handler
marshals the event onto the UI thread, using a delegate and BeginInvoke,
and appends the message to a rich text box.

The problem is now that the screen appears to be updating at a reasonable
pace, but it is clearly lagging a long way behind the messages being
supplied to it. At its worst, the background process finished, and it
took over five minutes for the screen to catch up. FIVE MINUTES! I think
I have got my pattern wrong here. I don't mind the screen lagging
slightly behind, but five minutes is just silly.

Going back to basics, I want to (need to) capture the messages passed in
all the events that the background thread raises, and I want to maintain
a display of these messages. Some messages will be coloured red to make
them stand out to the user, which is why I have used a rich text box.

Is there a better pattern for this type of application?

Incidentally, I ran this on a 3.0 GHz P4 Dell laptop, not the slower
Celeron m/c, so it will be much worse on the intended target m/c.

Charles
"Charles Law" <bl***@nowhere.com> wrote in message
news:uu***************@TK2MSFTNGP12.phx.gbl...
Hi guys

I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in
a specific time frame. The time when the process starts is not
especially important, but it must be complete within a small number of
seconds.

The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker
thread raises an event that is handled by the UI thread, to update a
rich text control with details of the completed operation. I am using a
rich text box so that when a failure occurs I can colour the message
red.

The problem I have is that sometimes, for no apparent reason, a step in
my process takes an inordinate amount of time, e.g 2.5 seconds instead
of perhaps 300 ms. When this happens, the complete process overruns my
time frame, and it has to be repeated. When I repeat the process there
is every chance that it completes in a realistic time, and all is well.
If I stop outputting to the screen, I do not get the problem.

When updating the screen on the UI thread, I use BeginInvoke, to marshal
the operation to the correct thread, and so as not to hold up the worker
thread, but this does not seem to help.

I realise that Windows (XP in this case) is not the ideal o/s for this
type of application, but does anyone have any ideas about how I could
make my application more deterministic? I am not certain what is going
on in these 2.5 seconds, so it might be useful if I could find out, but
I am not sure how I would do that.

TIA

Charles



Nov 22 '05 #54
Charles,

I still opt for the queue sample I gave you. Don't think about that as an
English queue.

In this case you put from every thread what is received as soon as possible.
Your mainthread is getting it out in the tempo he can process it.

I really think that this can make your processes more indipendent from
delays (although I agree that it never can solve that you cannot ring the
Big Ben 5 minutes over the hour).

There was as well an option for a stack in this thread, however the only
difference between a stack and a queue is that with a stack it goes last in
first out while the queue goes first in first out. (Still a little bit
English)

I think I wrote all the time queue well (it stays a terrible word)

:-)

Cor
Nov 22 '05 #55
Hi Cor

The reason I haven't tried the queue idea is that it seems to me to be, in
essence, what is happening when I use BeginInvoke.

With BeginInvoke, isn't it the case that the update gets queued until the UI
has time to put the message on the screen? In my scenario, the UI doesn't
get the time to do it very often, and when it does it is not quick enough.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Charles,

I still opt for the queue sample I gave you. Don't think about that as an
English queue.

In this case you put from every thread what is received as soon as
possible. Your mainthread is getting it out in the tempo he can process
it.

I really think that this can make your processes more indipendent from
delays (although I agree that it never can solve that you cannot ring the
Big Ben 5 minutes over the hour).

There was as well an option for a stack in this thread, however the only
difference between a stack and a queue is that with a stack it goes last
in first out while the queue goes first in first out. (Still a little bit
English)

I think I wrote all the time queue well (it stays a terrible word)

:-)

Cor

Nov 22 '05 #56
Charles,

Are we talking about the same, a queue is a datastore in memory, that can be
feed from thread a,b,c,d,e,f, and read by thread y where it deletes every
time one from the bottom.

Therefore makes in my opinion a very smooth process possible. I have used
this forever long ago in past when that had other names. (It was nice to
make asynchronous database and datacom controllers, now named multi tier
applications).

Cor
Nov 22 '05 #57
I think we are talking about the same thing. My doubt is whether it will be
an improvement on using BeginInvoke.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uN**************@TK2MSFTNGP14.phx.gbl...
Charles,

Are we talking about the same, a queue is a datastore in memory, that can
be feed from thread a,b,c,d,e,f, and read by thread y where it deletes
every time one from the bottom.

Therefore makes in my opinion a very smooth process possible. I have used
this forever long ago in past when that had other names. (It was nice to
make asynchronous database and datacom controllers, now named multi tier
applications).

Cor

Nov 22 '05 #58
Charles,
As I mentioned before Control.BeginInvoke uses the Win32 PostMessage API.
(you can use ILDASM or Reflector to verify)

The Win32 PostMessage places messages in the Win32 Message Queue.
http://msdn.microsoft.com/library/de...ostmessage.asp
Rolling your own queuing verses BeginInvoke may or may not help. Before I
attempted rolling my own as Cor suggests. I would want to be certain that is
the aspect of the entire process that is hurting performance. The 80/20
rule!

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
Hi Cor

The reason I haven't tried the queue idea is that it seems to me to be, in
essence, what is happening when I use BeginInvoke.

With BeginInvoke, isn't it the case that the update gets queued until the
UI has time to put the message on the screen? In my scenario, the UI
doesn't get the time to do it very often, and when it does it is not quick
enough.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Charles,

I still opt for the queue sample I gave you. Don't think about that as an
English queue.

In this case you put from every thread what is received as soon as
possible. Your mainthread is getting it out in the tempo he can process
it.

I really think that this can make your processes more indipendent from
delays (although I agree that it never can solve that you cannot ring the
Big Ben 5 minutes over the hour).

There was as well an option for a stack in this thread, however the only
difference between a stack and a queue is that with a stack it goes last
in first out while the queue goes first in first out. (Still a little bit
English)

I think I wrote all the time queue well (it stays a terrible word)

:-)

Cor


Nov 22 '05 #59
Hi Jay

I decided to test a theory ... here are some timings for updating a ListView
vs a RichTextBox (all timings in seconds)

Updates ListView RichTexBox ListView (no refresh)
100 0.5 0.28 ~0
1,000 5.42 4.0 0.25
10,000 52 197 2.56

I think this bears out the theory that the rich text box slows down as it
becomes filled up. The ListView update time is pretty linear, and for a
small number of updates is slower than the rich text box. The rich text box,
however, becomes abysmally slow as one adds a lot of text, ergo the ListView
is favourite. If one does not refresh the ListView after each update (not
possible with the RTB) then it is even quicker.

I think I will pursue the ListView approach :-)

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Charles,
As I mentioned before Control.BeginInvoke uses the Win32 PostMessage API.
(you can use ILDASM or Reflector to verify)

The Win32 PostMessage places messages in the Win32 Message Queue.
http://msdn.microsoft.com/library/de...ostmessage.asp
Rolling your own queuing verses BeginInvoke may or may not help. Before I
attempted rolling my own as Cor suggests. I would want to be certain that
is the aspect of the entire process that is hurting performance. The 80/20
rule!

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
Hi Cor

The reason I haven't tried the queue idea is that it seems to me to be,
in essence, what is happening when I use BeginInvoke.

With BeginInvoke, isn't it the case that the update gets queued until the
UI has time to put the message on the screen? In my scenario, the UI
doesn't get the time to do it very often, and when it does it is not
quick enough.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Charles,

I still opt for the queue sample I gave you. Don't think about that as
an English queue.

In this case you put from every thread what is received as soon as
possible. Your mainthread is getting it out in the tempo he can process
it.

I really think that this can make your processes more indipendent from
delays (although I agree that it never can solve that you cannot ring
the Big Ben 5 minutes over the hour).

There was as well an option for a stack in this thread, however the only
difference between a stack and a queue is that with a stack it goes last
in first out while the queue goes first in first out. (Still a little
bit English)

I think I wrote all the time queue well (it stays a terrible word)

:-)

Cor



Nov 22 '05 #60
CMM
Your problems seems to be basically this:

Your rich edit UI update is too sloooow. BeginInvoke queues up calls to
maintain thread safety. The best solution IMHO is the "polling" technique I
suggested earlier.

1) Worker thread SyncLocks a stack and pushes stuff into it.
2) UI Timer set at a reasonable interval (1 second maybe) SyncLocks the
stack, pops stuff out (*without* updating the UI I may add!) and lets go of
the SyncLock and then updates the UI... very nice, quick, and elegant. Much
better than updating the UI in realtime and on-demand... which apparently is
not working the way you want it to.
3) Everyone is happy. At most the UI is a second or so behind the
workthread's actual status.
"Charles Law" wrote:
I can't remember where I got up to with this thread, so this is a general
update on the problem.

I ran the application again this morning, against the real equipment. The
time critical parts of the process now seem to be more stable, after
implementing some of the suggestions, but at the severe detriment to the UI.
As mentioned before, the background process raises events when it wants to
notify the UI that something has happened, and the event handler marshals
the event onto the UI thread, using a delegate and BeginInvoke, and appends
the message to a rich text box.

The problem is now that the screen appears to be updating at a reasonable
pace, but it is clearly lagging a long way behind the messages being
supplied to it. At its worst, the background process finished, and it took
over five minutes for the screen to catch up. FIVE MINUTES! I think I have
got my pattern wrong here. I don't mind the screen lagging slightly behind,
but five minutes is just silly.

Going back to basics, I want to (need to) capture the messages passed in all
the events that the background thread raises, and I want to maintain a
display of these messages. Some messages will be coloured red to make them
stand out to the user, which is why I have used a rich text box.

Is there a better pattern for this type of application?

Incidentally, I ran this on a 3.0 GHz P4 Dell laptop, not the slower
Celeron m/c, so it will be much worse on the intended target m/c.

Charles
"Charles Law" <bl***@nowhere.com> wrote in message
news:uu***************@TK2MSFTNGP12.phx.gbl...
Hi guys

I have a time critical process, running on a worker thread. By "time
critical", I mean that certain parts of the process must be completed in a
specific time frame. The time when the process starts is not especially
important, but it must be complete within a small number of seconds.

The operations I am performing do not take a long time (hundreds of
milliseconds), but as each part of the process is complete, my worker
thread raises an event that is handled by the UI thread, to update a rich
text control with details of the completed operation. I am using a rich
text box so that when a failure occurs I can colour the message red.

The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms. When this happens, the complete process overruns my time
frame, and it has to be repeated. When I repeat the process there is every
chance that it completes in a realistic time, and all is well. If I stop
outputting to the screen, I do not get the problem.

When updating the screen on the UI thread, I use BeginInvoke, to marshal
the operation to the correct thread, and so as not to hold up the worker
thread, but this does not seem to help.

I realise that Windows (XP in this case) is not the ideal o/s for this
type of application, but does anyone have any ideas about how I could make
my application more deterministic? I am not certain what is going on in
these 2.5 seconds, so it might be useful if I could find out, but I am not
sure how I would do that.

TIA

Charles


Nov 22 '05 #61
CMM
The RichEdit box is slow because of the "Immutable String" factor.
string = string + newString becomes exponentially slower on each iteration.

1) Use the list view as you have already noted. But that's annoying when you
want to let the user copy and paste portions of the status.
or
2) Find a way to optimize the RichEdit control by passing your ENTIRE
contents with embedded RTF tags... rather than using its traditional
properties to manipulate its text selections. That way you can keep your
status messages in a stringbuilder... which is infinitely faster than the
update-as-go method that you have chosen.
or
3) Write your own usercontrol that basically just "writes and forgets",
using a StringBuilder, DrawString, maybe a Scrollbar control, and some smart
code. It's not hard at all.

"Charles Law" wrote:
Hi Jay

I decided to test a theory ... here are some timings for updating a ListView
vs a RichTextBox (all timings in seconds)

Updates ListView RichTexBox ListView (no refresh)
100 0.5 0.28 ~0
1,000 5.42 4.0 0.25
10,000 52 197 2.56

I think this bears out the theory that the rich text box slows down as it
becomes filled up. The ListView update time is pretty linear, and for a
small number of updates is slower than the rich text box. The rich text box,
however, becomes abysmally slow as one adds a lot of text, ergo the ListView
is favourite. If one does not refresh the ListView after each update (not
possible with the RTB) then it is even quicker.

I think I will pursue the ListView approach :-)

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Charles,
As I mentioned before Control.BeginInvoke uses the Win32 PostMessage API.
(you can use ILDASM or Reflector to verify)

The Win32 PostMessage places messages in the Win32 Message Queue.
http://msdn.microsoft.com/library/de...ostmessage.asp
Rolling your own queuing verses BeginInvoke may or may not help. Before I
attempted rolling my own as Cor suggests. I would want to be certain that
is the aspect of the entire process that is hurting performance. The 80/20
rule!

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:uo**************@TK2MSFTNGP14.phx.gbl...
Hi Cor

The reason I haven't tried the queue idea is that it seems to me to be,
in essence, what is happening when I use BeginInvoke.

With BeginInvoke, isn't it the case that the update gets queued until the
UI has time to put the message on the screen? In my scenario, the UI
doesn't get the time to do it very often, and when it does it is not
quick enough.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
Charles,

I still opt for the queue sample I gave you. Don't think about that as
an English queue.

In this case you put from every thread what is received as soon as
possible. Your mainthread is getting it out in the tempo he can process
it.

I really think that this can make your processes more indipendent from
delays (although I agree that it never can solve that you cannot ring
the Big Ben 5 minutes over the hour).

There was as well an option for a stack in this thread, however the only
difference between a stack and a queue is that with a stack it goes last
in first out while the queue goes first in first out. (Still a little
bit English)

I think I wrote all the time queue well (it stays a terrible word)

:-)

Cor



Nov 22 '05 #62
I have been experimenting some more, and have created a sample that queues
updates for a timer. The timer polls every second, and if it finds messages
in the queue it locks the queue, removes them all to an array, and unlocks
the queue. It then writes the messages to the rich text box and exits.

The queue is filled by a thread that just loops 1000 times, each time
locking the queue, adding a message and releasing the lock. So far so good.

If the FillQueue process is allowed to loop freely, it fills the queue in no
time at all (< 1 second). The timer then fires and takes 5 seconds to write
all the messages to the rich text box.

If the FillQueue process has a Sleep(20) in it (which is more representative
of my real-world scenario), then it takes 31 seconds to fill the queue, and
the timer function puts the messages on the screen (in a burst every
second), completing within 1 second of the FillQueue process finishing.

My second sample uses BeginInvoke. A class is created and its DoStuff method
is run on a new thread. DoStuff loops 1000 times, raising an event each time
round the loop. The event handler uses BeginInvoke to marshal to a function
that writes a message to a rich text box.

If DoStuff loops freely, it completes the loop in < 1 second. The screen
updates finish 5 seconds later.

If the DoStuff loop contains a Sleep(20), then it takes 31 seconds to
complete the loop, and the screen updates finish at exactly the same time.

From this simple test, it would seem to me that there is actually nothing to
choose between the two methods where speed is concerned. I haven't tried the
test with a loop count of 10,000, but I suspect that the results will be
comparable, and that the overriding issue will be the degradation of
performance of the rich text box as it fills up, as indicated by my earlier
test.

Following on from your other reply, I take the point about a listview
limiting the user's ability to copy sections of the output. The listview
also doesn't output as rtf, which is currently a nice feature because I can
retain the colour coding of the output. If there were a way of converting a
memory stream to rtf then that would be nice.

With regard to maintaining the rtf in a string builder, I have looked at
hand crafting rtf and it seems a lot to get to grips with. It also isn't as
generic a solution as I would like. I will look at this further though.

The idea of creating my own control has its appeal, because then I would
have total control. I will have a quick play and see where I get to.

Thanks.

Charles
"CMM" <CM*@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Your problems seems to be basically this:

Your rich edit UI update is too sloooow. BeginInvoke queues up calls to
maintain thread safety. The best solution IMHO is the "polling" technique
I
suggested earlier.

1) Worker thread SyncLocks a stack and pushes stuff into it.
2) UI Timer set at a reasonable interval (1 second maybe) SyncLocks the
stack, pops stuff out (*without* updating the UI I may add!) and lets go
of
the SyncLock and then updates the UI... very nice, quick, and elegant.
Much
better than updating the UI in realtime and on-demand... which apparently
is
not working the way you want it to.
3) Everyone is happy. At most the UI is a second or so behind the
workthread's actual status.
"Charles Law" wrote:
I can't remember where I got up to with this thread, so this is a general
update on the problem.

I ran the application again this morning, against the real equipment. The
time critical parts of the process now seem to be more stable, after
implementing some of the suggestions, but at the severe detriment to the
UI.
As mentioned before, the background process raises events when it wants
to
notify the UI that something has happened, and the event handler marshals
the event onto the UI thread, using a delegate and BeginInvoke, and
appends
the message to a rich text box.

The problem is now that the screen appears to be updating at a reasonable
pace, but it is clearly lagging a long way behind the messages being
supplied to it. At its worst, the background process finished, and it
took
over five minutes for the screen to catch up. FIVE MINUTES! I think I
have
got my pattern wrong here. I don't mind the screen lagging slightly
behind,
but five minutes is just silly.

Going back to basics, I want to (need to) capture the messages passed in
all
the events that the background thread raises, and I want to maintain a
display of these messages. Some messages will be coloured red to make
them
stand out to the user, which is why I have used a rich text box.

Is there a better pattern for this type of application?

Incidentally, I ran this on a 3.0 GHz P4 Dell laptop, not the slower
Celeron m/c, so it will be much worse on the intended target m/c.

Charles
"Charles Law" <bl***@nowhere.com> wrote in message
news:uu***************@TK2MSFTNGP12.phx.gbl...
> Hi guys
>
> I have a time critical process, running on a worker thread. By "time
> critical", I mean that certain parts of the process must be completed
> in a
> specific time frame. The time when the process starts is not especially
> important, but it must be complete within a small number of seconds.
>
> The operations I am performing do not take a long time (hundreds of
> milliseconds), but as each part of the process is complete, my worker
> thread raises an event that is handled by the UI thread, to update a
> rich
> text control with details of the completed operation. I am using a rich
> text box so that when a failure occurs I can colour the message red.
>
> The problem I have is that sometimes, for no apparent reason, a step in
> my
> process takes an inordinate amount of time, e.g 2.5 seconds instead of
> perhaps 300 ms. When this happens, the complete process overruns my
> time
> frame, and it has to be repeated. When I repeat the process there is
> every
> chance that it completes in a realistic time, and all is well. If I
> stop
> outputting to the screen, I do not get the problem.
>
> When updating the screen on the UI thread, I use BeginInvoke, to
> marshal
> the operation to the correct thread, and so as not to hold up the
> worker
> thread, but this does not seem to help.
>
> I realise that Windows (XP in this case) is not the ideal o/s for this
> type of application, but does anyone have any ideas about how I could
> make
> my application more deterministic? I am not certain what is going on in
> these 2.5 seconds, so it might be useful if I could find out, but I am
> not
> sure how I would do that.
>
> TIA
>
> Charles
>
>


Nov 22 '05 #63
Charles,

Your listview is of course your solution.

However reading this I get the idea that a solution could have been.

Use a mainthread that updates your rtfbox.

Use a workerthread that gets assynchronous the information from the
workerthreads and passes that in whatever way assynchronous to the updating
thread.

Use your worker threads.

Tell me what is wrong in this theoretical model.

:-)

Cor

Nov 22 '05 #64
Cor

I'm not sure I follow you entirely.
Use a mainthread that updates your rtfbox.
Do you mean as distinct from the UI thread? If it is, it will always have to
marshal back to the UI thread, so have I gained anything here?
Use a workerthread that gets assynchronous the information from the
workerthreads and passes that in whatever way assynchronous to the
updating thread.
This sounds like the queue sample I tried.
Use your worker threads.
?

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:um*************@tk2msftngp13.phx.gbl... Charles,

Your listview is of course your solution.

However reading this I get the idea that a solution could have been.

Use a mainthread that updates your rtfbox.

Use a workerthread that gets assynchronous the information from the
workerthreads and passes that in whatever way assynchronous to the
updating thread.

Use your worker threads.

Tell me what is wrong in this theoretical model.

:-)

Cor

Nov 22 '05 #65
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And let
the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor
Nov 22 '05 #66
Ok, yes. I see what you mean.

I think that one of the conclusions I should draw from this is that I am
probably outputting too much information in the first instance. I know that
sounds a bit like moving the goal posts, and that it doesn't solve the
underlying problem should I wish to output that amount of data, but I am
reminded of a similar situation put to me recently by a client. My answer
was to display less information and allow the user to drill down when
required, loading additional data as required. I think I should heed my own
advice.

I'm going to cache the large amount of output generated by the worker thread
and just output headings. If the user wishes to get more detail I will load
it when requested, in one hit. Nice and quick. I will also allow the entire
output to be saved, at which time I can generate the rtf. [I'm still looking
for a neat in-memory rtf generator. Maybe the rich text box will do it w/o
making it visible]

Thanks to everyone for their ideas and feedback.

And thanks Cor.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor

Nov 22 '05 #67
Cor & CMM,
This I can tell of course only now because we did not know that the RTFbox
was the bottleneck. I'm not convinced the bottleneck is the RTF box per se! Yes the ListView is
faster then the RTF Box, but that does not prove that the RTFBox is the
bottle neck!

The bottleneck may be the interop marshalling from .NET world to the Win32
RTF Textbox world. In which case both the RTFBox & the ListView will have a
problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting with
memory.

The bottleneck may be some unrelated program that happens to be running.

The bottleneck may be some unforseen disk access, such as page swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to accurately
identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have seen
where one method may be faster for small number and/or size of objects,
suddenly becomes painfully slow for large number and/or size of objects...

As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no apparent
reason" would suggest to me that it is not specifically the RTF or the
BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl... Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor

Nov 22 '05 #68
CMM
Good job testing out all of our flakey ideas. This was a very interesting and
enlightening thread.

Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties to
set your formatting?
This is your bottleneck I take it as it will exponentially become slower as
the text increases. Have you taken a look at the RichTextBox's RTF property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes that
you would just dump into the control in one swoop (Text=sb.ToString() )

RTF codes aren't that difficult... it's a lot like HTML... check out this
link to get you started:
http://msdn.microsoft.com/library/de...isualBasic.asp
"Charles Law" wrote:
Ok, yes. I see what you mean.

I think that one of the conclusions I should draw from this is that I am
probably outputting too much information in the first instance. I know that
sounds a bit like moving the goal posts, and that it doesn't solve the
underlying problem should I wish to output that amount of data, but I am
reminded of a similar situation put to me recently by a client. My answer
was to display less information and allow the user to drill down when
required, loading additional data as required. I think I should heed my own
advice.

I'm going to cache the large amount of output generated by the worker thread
and just output headings. If the user wishes to get more detail I will load
it when requested, in one hit. Nice and quick. I will also allow the entire
output to be saved, at which time I can generate the rtf. [I'm still looking
for a neat in-memory rtf generator. Maybe the rich text box will do it w/o
making it visible]

Thanks to everyone for their ideas and feedback.

And thanks Cor.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor


Nov 22 '05 #69
CMM
Correction: .Rtf = sb.ToString()

"CMM" wrote:
Good job testing out all of our flakey ideas. This was a very interesting and
enlightening thread.

Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties to
set your formatting?
This is your bottleneck I take it as it will exponentially become slower as
the text increases. Have you taken a look at the RichTextBox's RTF property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes that
you would just dump into the control in one swoop (Text=sb.ToString() )

RTF codes aren't that difficult... it's a lot like HTML... check out this
link to get you started:
http://msdn.microsoft.com/library/de...isualBasic.asp
"Charles Law" wrote:
Ok, yes. I see what you mean.

I think that one of the conclusions I should draw from this is that I am
probably outputting too much information in the first instance. I know that
sounds a bit like moving the goal posts, and that it doesn't solve the
underlying problem should I wish to output that amount of data, but I am
reminded of a similar situation put to me recently by a client. My answer
was to display less information and allow the user to drill down when
required, loading additional data as required. I think I should heed my own
advice.

I'm going to cache the large amount of output generated by the worker thread
and just output headings. If the user wishes to get more detail I will load
it when requested, in one hit. Nice and quick. I will also allow the entire
output to be saved, at which time I can generate the rtf. [I'm still looking
for a neat in-memory rtf generator. Maybe the rich text box will do it w/o
making it visible]

Thanks to everyone for their ideas and feedback.

And thanks Cor.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor


Nov 22 '05 #70
CMM
Agreed. It seems likely Charles probably has *multiple* bottlenecks
actually.... (I think) the richedit control being the most obvious and the GC
(lots of New Object instantiation / releasing, etc) being the more subtle one.

"Jay B. Harlow [MVP - Outlook]" wrote:
Cor & CMM,
This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

I'm not convinced the bottleneck is the RTF box per se! Yes the ListView is
faster then the RTF Box, but that does not prove that the RTFBox is the
bottle neck!

The bottleneck may be the interop marshalling from .NET world to the Win32
RTF Textbox world. In which case both the RTFBox & the ListView will have a
problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting with
memory.

The bottleneck may be some unrelated program that happens to be running.

The bottleneck may be some unforseen disk access, such as page swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to accurately
identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have seen
where one method may be faster for small number and/or size of objects,
suddenly becomes painfully slow for large number and/or size of objects...

As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no apparent
reason" would suggest to me that it is not specifically the RTF or the
BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well seperated
threads.

This I can tell of course only now because we did not know that the RTFbox
was the bottleneck.

Describes this better what I mean?

Cor


Nov 22 '05 #71
Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties
to
set your formatting?
The actual code is below (TestResults is the rich text box)

<code>
Private Sub UpdateStatus(ByVal s As String)

Dim selectStart As Integer

With TestResults
.SuspendLayout()

.Focus()

selectStart = .TextLength

' Append the status text to the results window
.AppendText(s & EOL)

' Highlight failed tests in red
.SelectionColor = Color.Red

.Select(selectStart, s.Length)

.ClearUndo()

' Keep the most recent addition in view
.Select(.TextLength, 0)
.ScrollToCaret()

.ResumeLayout()
End With

End Sub
</code>
... Have you taken a look at the RichTextBox's RTF property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes
that
you would just dump into the control in one swoop (Text=sb.ToString() )
Yes, I did look at the RTF property. I must admit that, despite your
reassurances, it looked like a lot of work. I know HTML well, but it did
not seem quite so straight forward on first inspection. It may still be
worth a punt though.

Charles
"CMM" <CM*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com... Good job testing out all of our flakey ideas. This was a very interesting
and
enlightening thread.

Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties
to
set your formatting?
This is your bottleneck I take it as it will exponentially become slower
as
the text increases. Have you taken a look at the RichTextBox's RTF
property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes
that
you would just dump into the control in one swoop (Text=sb.ToString() )

RTF codes aren't that difficult... it's a lot like HTML... check out this
link to get you started:
http://msdn.microsoft.com/library/de...isualBasic.asp
"Charles Law" wrote:
Ok, yes. I see what you mean.

I think that one of the conclusions I should draw from this is that I am
probably outputting too much information in the first instance. I know
that
sounds a bit like moving the goal posts, and that it doesn't solve the
underlying problem should I wish to output that amount of data, but I am
reminded of a similar situation put to me recently by a client. My answer
was to display less information and allow the user to drill down when
required, loading additional data as required. I think I should heed my
own
advice.

I'm going to cache the large amount of output generated by the worker
thread
and just output headings. If the user wishes to get more detail I will
load
it when requested, in one hit. Nice and quick. I will also allow the
entire
output to be saved, at which time I can generate the rtf. [I'm still
looking
for a neat in-memory rtf generator. Maybe the rich text box will do it
w/o
making it visible]

Thanks to everyone for their ideas and feedback.

And thanks Cor.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
> Charles,
>
> It has not to do with the way I told or others told
>
> This has to do with the design.
>
> When you use 3 instead of 2 tiers than you can let your loading of your
> RTFBox go smooth without any waiting in a seperated thread. Collect the
> information for that in another tier as well in a seperated thread. And
> let the worker tiers get the information for the last in as well
> seperated
> threads.
>
> This I can tell of course only now because we did not know that the
> RTFbox
> was the bottleneck.
>
> Describes this better what I mean?
>
> Cor
>


Nov 22 '05 #72
Hi Jay

I am convinced that the RichTextBox is /a/ bottleneck.
The bottleneck may be the GC!
Interestingly, I noticed that in my tests, there was a noticeable pause
early in the updating of he RTB. It contained only a dozen lines, but I
detected a half-second pause as the screen was updating. This was
reproducible. There is every chance that this would re-occur later, and when
the RTB is fuller, the delay could be longer.
The bottleneck may actually be the way Charles' program is interacting
with memory.
In my real-world application this is true. But my samples are trivial.
Object creation is minimal, but it is true that in the event sample, an
EventArgs object is created every time an event is raised.
The bottleneck may be some unrelated program that happens to be running.
If this were true, I would expect it to affect both samples equally.
The bottleneck may be some unforeseen disk access, such as page swapping.
As above.
The bottleneck may be any number of other things...
I appreciate that you are illustrating the general point that the problem
might lie elsewhere, somewhere that we have not considered, but I have
attempted to make all things equal, so that the only differences in my
samples are down to the detail of the test that I am conducting.
Hence my suggestion to use CLR Profiler & other tools to try to accurately
identify where specifically the bottle neck is.
I have had another look at the CLR Profiler and I can only say that I
understand now why it is free. There are many diverse requirements for
memory profiling, but as far as I can see none of them are intuitively
handled by the CLR Profiler.
As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.
Agreed, But it may be that because of the way the RTB is implemented there
is a lot of memory manipulation going on that impairs performance.
In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.
Also agreed.

My gut feeling is that the RTB is not the best tool for the job that I
started out with. That said, the job I started out with is probably quite a
stretch full-stop. I suspect that I should take more control over the
delivery of status to the user based on the amount of information I am
trying to deliver. I am inclined to believe that the fundamental flaw is
that I am trying to present too much information in a short space of time,
with controls that are not designed for that kind of performance. I could
probably write a more efficient control, but there would be a lot of
functionality to reproduce, and it may not be necessary if I modify slightly
my contact with the user.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Cor & CMM,
This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.

I'm not convinced the bottleneck is the RTF box per se! Yes the ListView
is faster then the RTF Box, but that does not prove that the RTFBox is the
bottle neck!

The bottleneck may be the interop marshalling from .NET world to the Win32
RTF Textbox world. In which case both the RTFBox & the ListView will have
a problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting
with memory.

The bottleneck may be some unrelated program that happens to be running.

The bottleneck may be some unforseen disk access, such as page swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to accurately
identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have
seen where one method may be faster for small number and/or size of
objects, suddenly becomes painfully slow for large number and/or size of
objects...

As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well
seperated threads.

This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.

Describes this better what I mean?

Cor


Nov 22 '05 #73
CMM
I did a quick test to get a feel for how fast the RichTextBox would be using
the Rtf property rather then the Text/Selection properties. It was still way
slooooww. I say ditch the RichTextBox control.
"Charles Law" wrote:
Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties
to
set your formatting?


The actual code is below (TestResults is the rich text box)

<code>
Private Sub UpdateStatus(ByVal s As String)

Dim selectStart As Integer

With TestResults
.SuspendLayout()

.Focus()

selectStart = .TextLength

' Append the status text to the results window
.AppendText(s & EOL)

' Highlight failed tests in red
.SelectionColor = Color.Red

.Select(selectStart, s.Length)

.ClearUndo()

' Keep the most recent addition in view
.Select(.TextLength, 0)
.ScrollToCaret()

.ResumeLayout()
End With

End Sub
</code>
... Have you taken a look at the RichTextBox's RTF property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes
that
you would just dump into the control in one swoop (Text=sb.ToString() )


Yes, I did look at the RTF property. I must admit that, despite your
reassurances, it looked like a lot of work. I know HTML well, but it did
not seem quite so straight forward on first inspection. It may still be
worth a punt though.

Charles
"CMM" <CM*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Good job testing out all of our flakey ideas. This was a very interesting
and
enlightening thread.

Just one more suggestion: You are updating the RichTextbox by doing
something like .Text = .Text + s and then using the Selection properties
to
set your formatting?
This is your bottleneck I take it as it will exponentially become slower
as
the text increases. Have you taken a look at the RichTextBox's RTF
property?
This lets you set the whole text with codes... and would allow you to
maintain your status messages in a StringBuilder complete with RTF codes
that
you would just dump into the control in one swoop (Text=sb.ToString() )

RTF codes aren't that difficult... it's a lot like HTML... check out this
link to get you started:
http://msdn.microsoft.com/library/de...isualBasic.asp
"Charles Law" wrote:
Ok, yes. I see what you mean.

I think that one of the conclusions I should draw from this is that I am
probably outputting too much information in the first instance. I know
that
sounds a bit like moving the goal posts, and that it doesn't solve the
underlying problem should I wish to output that amount of data, but I am
reminded of a similar situation put to me recently by a client. My answer
was to display less information and allow the user to drill down when
required, loading additional data as required. I think I should heed my
own
advice.

I'm going to cache the large amount of output generated by the worker
thread
and just output headings. If the user wishes to get more detail I will
load
it when requested, in one hit. Nice and quick. I will also allow the
entire
output to be saved, at which time I can generate the rtf. [I'm still
looking
for a neat in-memory rtf generator. Maybe the rich text box will do it
w/o
making it visible]

Thanks to everyone for their ideas and feedback.

And thanks Cor.

Charles
"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
> Charles,
>
> It has not to do with the way I told or others told
>
> This has to do with the design.
>
> When you use 3 instead of 2 tiers than you can let your loading of your
> RTFBox go smooth without any waiting in a seperated thread. Collect the
> information for that in another tier as well in a seperated thread. And
> let the worker tiers get the information for the last in as well
> seperated
> threads.
>
> This I can tell of course only now because we did not know that the
> RTFbox
> was the bottleneck.
>
> Describes this better what I mean?
>
> Cor
>


Nov 22 '05 #74
Consider it ditched :-)
"CMM" <CM*@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
I did a quick test to get a feel for how fast the RichTextBox would be
using
the Rtf property rather then the Text/Selection properties. It was still
way
slooooww. I say ditch the RichTextBox control.
"Charles Law" wrote:
> Just one more suggestion: You are updating the RichTextbox by doing
> something like .Text = .Text + s and then using the Selection
> properties
> to
> set your formatting?


The actual code is below (TestResults is the rich text box)

<code>
Private Sub UpdateStatus(ByVal s As String)

Dim selectStart As Integer

With TestResults
.SuspendLayout()

.Focus()

selectStart = .TextLength

' Append the status text to the results window
.AppendText(s & EOL)

' Highlight failed tests in red
.SelectionColor = Color.Red

.Select(selectStart, s.Length)

.ClearUndo()

' Keep the most recent addition in view
.Select(.TextLength, 0)
.ScrollToCaret()

.ResumeLayout()
End With

End Sub
</code>
> ... Have you taken a look at the RichTextBox's RTF property?
> This lets you set the whole text with codes... and would allow you to
> maintain your status messages in a StringBuilder complete with RTF
> codes
> that
> you would just dump into the control in one swoop (Text=sb.ToString() )


Yes, I did look at the RTF property. I must admit that, despite your
reassurances, it looked like a lot of work. I know HTML well, but it did
not seem quite so straight forward on first inspection. It may still be
worth a punt though.

Charles
"CMM" <CM*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
> Good job testing out all of our flakey ideas. This was a very
> interesting
> and
> enlightening thread.
>
> Just one more suggestion: You are updating the RichTextbox by doing
> something like .Text = .Text + s and then using the Selection
> properties
> to
> set your formatting?
> This is your bottleneck I take it as it will exponentially become
> slower
> as
> the text increases. Have you taken a look at the RichTextBox's RTF
> property?
> This lets you set the whole text with codes... and would allow you to
> maintain your status messages in a StringBuilder complete with RTF
> codes
> that
> you would just dump into the control in one swoop (Text=sb.ToString() )
>
> RTF codes aren't that difficult... it's a lot like HTML... check out
> this
> link to get you started:
> http://msdn.microsoft.com/library/de...isualBasic.asp
>
>
> "Charles Law" wrote:
>
>> Ok, yes. I see what you mean.
>>
>> I think that one of the conclusions I should draw from this is that I
>> am
>> probably outputting too much information in the first instance. I know
>> that
>> sounds a bit like moving the goal posts, and that it doesn't solve the
>> underlying problem should I wish to output that amount of data, but I
>> am
>> reminded of a similar situation put to me recently by a client. My
>> answer
>> was to display less information and allow the user to drill down when
>> required, loading additional data as required. I think I should heed
>> my
>> own
>> advice.
>>
>> I'm going to cache the large amount of output generated by the worker
>> thread
>> and just output headings. If the user wishes to get more detail I will
>> load
>> it when requested, in one hit. Nice and quick. I will also allow the
>> entire
>> output to be saved, at which time I can generate the rtf. [I'm still
>> looking
>> for a neat in-memory rtf generator. Maybe the rich text box will do it
>> w/o
>> making it visible]
>>
>> Thanks to everyone for their ideas and feedback.
>>
>> And thanks Cor.
>>
>> Charles
>>
>>
>> "Cor Ligthert" <no************@planet.nl> wrote in message
>> news:en**************@TK2MSFTNGP14.phx.gbl...
>> > Charles,
>> >
>> > It has not to do with the way I told or others told
>> >
>> > This has to do with the design.
>> >
>> > When you use 3 instead of 2 tiers than you can let your loading of
>> > your
>> > RTFBox go smooth without any waiting in a seperated thread. Collect
>> > the
>> > information for that in another tier as well in a seperated thread.
>> > And
>> > let the worker tiers get the information for the last in as well
>> > seperated
>> > threads.
>> >
>> > This I can tell of course only now because we did not know that the
>> > RTFbox
>> > was the bottleneck.
>> >
>> > Describes this better what I mean?
>> >
>> > Cor
>> >
>>
>>
>>


Nov 22 '05 #75
Jay,

My idea was only based what Charles was telling. I have no tools too show
that he could be wrong. Given that situation, I would make that redesign I
suggested..

:-)

Cor
Nov 22 '05 #76
Charles,
My gut feeling is that the RTB is not the best tool for the job that I
started out with. My gut feeling is the RTB is not the best tool for the job. However this is
from a presentation standpoint & not a performance standpoint!

It sounds like you are displaying when a series of events occurred in a
process, a ListView (in Details mode) or a Grid sounds like a better fit.
I am inclined to believe that the fundamental flaw is that I am trying to
present too much information in a short space of time, Agreed
with controls that are not designed for that kind of performance. Depending on how short the "short space of time" is, there may not be a
control worthy of the performance...
Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Jay

I am convinced that the RichTextBox is /a/ bottleneck.
The bottleneck may be the GC!


Interestingly, I noticed that in my tests, there was a noticeable pause
early in the updating of he RTB. It contained only a dozen lines, but I
detected a half-second pause as the screen was updating. This was
reproducible. There is every chance that this would re-occur later, and
when the RTB is fuller, the delay could be longer.
The bottleneck may actually be the way Charles' program is interacting
with memory.


In my real-world application this is true. But my samples are trivial.
Object creation is minimal, but it is true that in the event sample, an
EventArgs object is created every time an event is raised.
The bottleneck may be some unrelated program that happens to be running.


If this were true, I would expect it to affect both samples equally.
The bottleneck may be some unforeseen disk access, such as page swapping.


As above.
The bottleneck may be any number of other things...


I appreciate that you are illustrating the general point that the problem
might lie elsewhere, somewhere that we have not considered, but I have
attempted to make all things equal, so that the only differences in my
samples are down to the detail of the test that I am conducting.
Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.


I have had another look at the CLR Profiler and I can only say that I
understand now why it is free. There are many diverse requirements for
memory profiling, but as far as I can see none of them are intuitively
handled by the CLR Profiler.
As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.


Agreed, But it may be that because of the way the RTB is implemented there
is a lot of memory manipulation going on that impairs performance.
In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.


Also agreed.

My gut feeling is that the RTB is not the best tool for the job that I
started out with. That said, the job I started out with is probably quite
a stretch full-stop. I suspect that I should take more control over the
delivery of status to the user based on the amount of information I am
trying to deliver. I am inclined to believe that the fundamental flaw is
that I am trying to present too much information in a short space of time,
with controls that are not designed for that kind of performance. I could
probably write a more efficient control, but there would be a lot of
functionality to reproduce, and it may not be necessary if I modify
slightly my contact with the user.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Cor & CMM,
This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.

I'm not convinced the bottleneck is the RTF box per se! Yes the ListView
is faster then the RTF Box, but that does not prove that the RTFBox is
the bottle neck!

The bottleneck may be the interop marshalling from .NET world to the
Win32 RTF Textbox world. In which case both the RTFBox & the ListView
will have a problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting
with memory.

The bottleneck may be some unrelated program that happens to be running.

The bottleneck may be some unforseen disk access, such as page swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have
seen where one method may be faster for small number and/or size of
objects, suddenly becomes painfully slow for large number and/or size of
objects...

As Charles initially stated "The problem I have is that sometimes, for no
apparent reason, a step in my process takes an inordinate amount of time,
e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects, however
the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well
seperated threads.

This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.

Describes this better what I mean?

Cor



Nov 22 '05 #77
Jay

I have been toying with trying a grid, now that I have moved away from the
RTB, but I fear that whilst the performance of the ListView is excellent, I
might sacrifice some of that performance by moving to a more complex
control.

The downside of abandoning the RTB is that I have lost the ability to save
the information with its colour highlighting. I have tried writing each
line, with colouring, to an invisible RTB at the end of the whole process so
that I can use its SaveFile method to save the RTF, but it takes minutes to
execute, so is not an option.

I could serialise the ListView to an xml file, with attributes to indicate
colour (or status, actually), and reload very quickly, but my user does not
have anything to display it other than my program. RTF seemed the best way
to include colouring so that it could be loaded by Word, for example, and
viewed and printed easily.

Isn't it always the way: one solves one problem often at the expense of
creating another.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Oc*************@TK2MSFTNGP15.phx.gbl...
Charles,
My gut feeling is that the RTB is not the best tool for the job that I
started out with.

My gut feeling is the RTB is not the best tool for the job. However this
is from a presentation standpoint & not a performance standpoint!

It sounds like you are displaying when a series of events occurred in a
process, a ListView (in Details mode) or a Grid sounds like a better fit.
I am inclined to believe that the fundamental flaw is that I am trying to
present too much information in a short space of time,

Agreed
with controls that are not designed for that kind of performance.

Depending on how short the "short space of time" is, there may not be a
control worthy of the performance...
Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Jay

I am convinced that the RichTextBox is /a/ bottleneck.
The bottleneck may be the GC!


Interestingly, I noticed that in my tests, there was a noticeable pause
early in the updating of he RTB. It contained only a dozen lines, but I
detected a half-second pause as the screen was updating. This was
reproducible. There is every chance that this would re-occur later, and
when the RTB is fuller, the delay could be longer.
The bottleneck may actually be the way Charles' program is interacting
with memory.


In my real-world application this is true. But my samples are trivial.
Object creation is minimal, but it is true that in the event sample, an
EventArgs object is created every time an event is raised.
The bottleneck may be some unrelated program that happens to be running.


If this were true, I would expect it to affect both samples equally.
The bottleneck may be some unforeseen disk access, such as page
swapping.


As above.
The bottleneck may be any number of other things...


I appreciate that you are illustrating the general point that the problem
might lie elsewhere, somewhere that we have not considered, but I have
attempted to make all things equal, so that the only differences in my
samples are down to the detail of the test that I am conducting.
Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.


I have had another look at the CLR Profiler and I can only say that I
understand now why it is free. There are many diverse requirements for
memory profiling, but as far as I can see none of them are intuitively
handled by the CLR Profiler.
As Charles initially stated "The problem I have is that sometimes, for
no apparent reason, a step in my process takes an inordinate amount of
time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.


Agreed, But it may be that because of the way the RTB is implemented
there is a lot of memory manipulation going on that impairs performance.
In other words BeginInvoke & the RTF Box are both still suspects,
however the jury (CLR Profiler) has not convicted them of any crime.


Also agreed.

My gut feeling is that the RTB is not the best tool for the job that I
started out with. That said, the job I started out with is probably quite
a stretch full-stop. I suspect that I should take more control over the
delivery of status to the user based on the amount of information I am
trying to deliver. I am inclined to believe that the fundamental flaw is
that I am trying to present too much information in a short space of
time, with controls that are not designed for that kind of performance. I
could probably write a more efficient control, but there would be a lot
of functionality to reproduce, and it may not be necessary if I modify
slightly my contact with the user.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Cor & CMM,
This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.
I'm not convinced the bottleneck is the RTF box per se! Yes the ListView
is faster then the RTF Box, but that does not prove that the RTFBox is
the bottle neck!

The bottleneck may be the interop marshalling from .NET world to the
Win32 RTF Textbox world. In which case both the RTFBox & the ListView
will have a problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting
with memory.

The bottleneck may be some unrelated program that happens to be running.

The bottleneck may be some unforseen disk access, such as page swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have
seen where one method may be faster for small number and/or size of
objects, suddenly becomes painfully slow for large number and/or size of
objects...

As Charles initially stated "The problem I have is that sometimes, for
no apparent reason, a step in my process takes an inordinate amount of
time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for no
apparent reason" would suggest to me that it is not specifically the RTF
or the BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects,
however the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
Charles,

It has not to do with the way I told or others told

This has to do with the design.

When you use 3 instead of 2 tiers than you can let your loading of your
RTFBox go smooth without any waiting in a seperated thread. Collect the
information for that in another tier as well in a seperated thread. And
let the worker tiers get the information for the last in as well
seperated threads.

This I can tell of course only now because we did not know that the
RTFbox was the bottleneck.

Describes this better what I mean?

Cor



Nov 22 '05 #78
Charles,
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|

I would half expect DataGrid to be slower then ListView just by the very
nature of the controls.

It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:ud**************@TK2MSFTNGP15.phx.gbl...
Jay

I have been toying with trying a grid, now that I have moved away from the
RTB, but I fear that whilst the performance of the ListView is excellent,
I might sacrifice some of that performance by moving to a more complex
control.

The downside of abandoning the RTB is that I have lost the ability to save
the information with its colour highlighting. I have tried writing each
line, with colouring, to an invisible RTB at the end of the whole process
so that I can use its SaveFile method to save the RTF, but it takes
minutes to execute, so is not an option.

I could serialise the ListView to an xml file, with attributes to indicate
colour (or status, actually), and reload very quickly, but my user does
not have anything to display it other than my program. RTF seemed the best
way to include colouring so that it could be loaded by Word, for example,
and viewed and printed easily.

Isn't it always the way: one solves one problem often at the expense of
creating another.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Oc*************@TK2MSFTNGP15.phx.gbl...
Charles,
My gut feeling is that the RTB is not the best tool for the job that I
started out with.

My gut feeling is the RTB is not the best tool for the job. However this
is from a presentation standpoint & not a performance standpoint!

It sounds like you are displaying when a series of events occurred in a
process, a ListView (in Details mode) or a Grid sounds like a better fit.
I am inclined to believe that the fundamental flaw is that I am trying
to present too much information in a short space of time,

Agreed
with controls that are not designed for that kind of performance.

Depending on how short the "short space of time" is, there may not be a
control worthy of the performance...
Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Jay

I am convinced that the RichTextBox is /a/ bottleneck.

The bottleneck may be the GC!

Interestingly, I noticed that in my tests, there was a noticeable pause
early in the updating of he RTB. It contained only a dozen lines, but I
detected a half-second pause as the screen was updating. This was
reproducible. There is every chance that this would re-occur later, and
when the RTB is fuller, the delay could be longer.

The bottleneck may actually be the way Charles' program is interacting
with memory.

In my real-world application this is true. But my samples are trivial.
Object creation is minimal, but it is true that in the event sample, an
EventArgs object is created every time an event is raised.

The bottleneck may be some unrelated program that happens to be
running.

If this were true, I would expect it to affect both samples equally.

The bottleneck may be some unforeseen disk access, such as page
swapping.

As above.

The bottleneck may be any number of other things...

I appreciate that you are illustrating the general point that the
problem might lie elsewhere, somewhere that we have not considered, but
I have attempted to make all things equal, so that the only differences
in my samples are down to the detail of the test that I am conducting.

Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.

I have had another look at the CLR Profiler and I can only say that I
understand now why it is free. There are many diverse requirements for
memory profiling, but as far as I can see none of them are intuitively
handled by the CLR Profiler.

As Charles initially stated "The problem I have is that sometimes, for
no apparent reason, a step in my process takes an inordinate amount of
time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for
no apparent reason" would suggest to me that it is not specifically the
RTF or the BeginInvoke, although it could be.

Agreed, But it may be that because of the way the RTB is implemented
there is a lot of memory manipulation going on that impairs performance.

In other words BeginInvoke & the RTF Box are both still suspects,
however the jury (CLR Profiler) has not convicted them of any crime.

Also agreed.

My gut feeling is that the RTB is not the best tool for the job that I
started out with. That said, the job I started out with is probably
quite a stretch full-stop. I suspect that I should take more control
over the delivery of status to the user based on the amount of
information I am trying to deliver. I am inclined to believe that the
fundamental flaw is that I am trying to present too much information in
a short space of time, with controls that are not designed for that kind
of performance. I could probably write a more efficient control, but
there would be a lot of functionality to reproduce, and it may not be
necessary if I modify slightly my contact with the user.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Cor & CMM,
> This I can tell of course only now because we did not know that the
> RTFbox was the bottleneck.
I'm not convinced the bottleneck is the RTF box per se! Yes the
ListView is faster then the RTF Box, but that does not prove that the
RTFBox is the bottle neck!

The bottleneck may be the interop marshalling from .NET world to the
Win32 RTF Textbox world. In which case both the RTFBox & the ListView
will have a problem as both are based on "native" Win32 controls.

The bottleneck may be the GC!

The bottleneck may actually be the way Charles' program is interacting
with memory.

The bottleneck may be some unrelated program that happens to be
running.

The bottleneck may be some unforseen disk access, such as page
swapping.

The bottleneck may be any number of other things...

Hence my suggestion to use CLR Profiler & other tools to try to
accurately identify where specifically the bottle neck is.

Or at the very least two methods & see which is faster. However I have
seen where one method may be faster for small number and/or size of
objects, suddenly becomes painfully slow for large number and/or size
of objects...

As Charles initially stated "The problem I have is that sometimes, for
no apparent reason, a step in my process takes an inordinate amount of
time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for
no apparent reason" would suggest to me that it is not specifically the
RTF or the BeginInvoke, although it could be.

In other words BeginInvoke & the RTF Box are both still suspects,
however the jury (CLR Profiler) has not convicted them of any crime.

Just a thought
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:en**************@TK2MSFTNGP14.phx.gbl...
> Charles,
>
> It has not to do with the way I told or others told
>
> This has to do with the design.
>
> When you use 3 instead of 2 tiers than you can let your loading of
> your RTFBox go smooth without any waiting in a seperated thread.
> Collect the information for that in another tier as well in a
> seperated thread. And let the worker tiers get the information for the
> last in as well seperated threads.
>
> This I can tell of course only now because we did not know that the
> RTFbox was the bottleneck.
>
> Describes this better what I mean?
>
> Cor
>



Nov 22 '05 #79

Jay
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|
I wasn't aware that I was. Surely the illness is displaying too much data,
which I am addressing. I was just bemoaning the fact that the original
solution had its benefits, so now I have to regain those benefits by some
other means.
It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...
I don't actually want to go down this route. I fancy someone somewhere must
have done this already. I just need to find it! You have prompted me to try
html though. That could be quicker and, as I know html, easier too. It
doesn't have to be rtf. The main requirement is that however I save the
data, it can be displayed outside my app, but retaining the colour coding.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl... Charles,
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|

I would half expect DataGrid to be slower then ListView just by the very
nature of the controls.

It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...

Hope this helps
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:ud**************@TK2MSFTNGP15.phx.gbl...
Jay

I have been toying with trying a grid, now that I have moved away from
the RTB, but I fear that whilst the performance of the ListView is
excellent, I might sacrifice some of that performance by moving to a more
complex control.

The downside of abandoning the RTB is that I have lost the ability to
save the information with its colour highlighting. I have tried writing
each line, with colouring, to an invisible RTB at the end of the whole
process so that I can use its SaveFile method to save the RTF, but it
takes minutes to execute, so is not an option.

I could serialise the ListView to an xml file, with attributes to
indicate colour (or status, actually), and reload very quickly, but my
user does not have anything to display it other than my program. RTF
seemed the best way to include colouring so that it could be loaded by
Word, for example, and viewed and printed easily.

Isn't it always the way: one solves one problem often at the expense of
creating another.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Oc*************@TK2MSFTNGP15.phx.gbl...
Charles,
My gut feeling is that the RTB is not the best tool for the job that I
started out with.
My gut feeling is the RTB is not the best tool for the job. However this
is from a presentation standpoint & not a performance standpoint!

It sounds like you are displaying when a series of events occurred in a
process, a ListView (in Details mode) or a Grid sounds like a better
fit.

I am inclined to believe that the fundamental flaw is that I am trying
to present too much information in a short space of time,
Agreed

with controls that are not designed for that kind of performance.
Depending on how short the "short space of time" is, there may not be a
control worthy of the performance...
Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Jay

I am convinced that the RichTextBox is /a/ bottleneck.

> The bottleneck may be the GC!

Interestingly, I noticed that in my tests, there was a noticeable pause
early in the updating of he RTB. It contained only a dozen lines, but I
detected a half-second pause as the screen was updating. This was
reproducible. There is every chance that this would re-occur later, and
when the RTB is fuller, the delay could be longer.

> The bottleneck may actually be the way Charles' program is interacting
> with memory.

In my real-world application this is true. But my samples are trivial.
Object creation is minimal, but it is true that in the event sample, an
EventArgs object is created every time an event is raised.

> The bottleneck may be some unrelated program that happens to be
> running.

If this were true, I would expect it to affect both samples equally.

> The bottleneck may be some unforeseen disk access, such as page
> swapping.

As above.

> The bottleneck may be any number of other things...

I appreciate that you are illustrating the general point that the
problem might lie elsewhere, somewhere that we have not considered, but
I have attempted to make all things equal, so that the only differences
in my samples are down to the detail of the test that I am conducting.

> Hence my suggestion to use CLR Profiler & other tools to try to
> accurately identify where specifically the bottle neck is.

I have had another look at the CLR Profiler and I can only say that I
understand now why it is free. There are many diverse requirements for
memory profiling, but as far as I can see none of them are intuitively
handled by the CLR Profiler.

> As Charles initially stated "The problem I have is that sometimes, for
> no apparent reason, a step in my process takes an inordinate amount of
> time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for
> no apparent reason" would suggest to me that it is not specifically
> the RTF or the BeginInvoke, although it could be.

Agreed, But it may be that because of the way the RTB is implemented
there is a lot of memory manipulation going on that impairs
performance.

> In other words BeginInvoke & the RTF Box are both still suspects,
> however the jury (CLR Profiler) has not convicted them of any crime.

Also agreed.

My gut feeling is that the RTB is not the best tool for the job that I
started out with. That said, the job I started out with is probably
quite a stretch full-stop. I suspect that I should take more control
over the delivery of status to the user based on the amount of
information I am trying to deliver. I am inclined to believe that the
fundamental flaw is that I am trying to present too much information in
a short space of time, with controls that are not designed for that
kind of performance. I could probably write a more efficient control,
but there would be a lot of functionality to reproduce, and it may not
be necessary if I modify slightly my contact with the user.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
> Cor & CMM,
>> This I can tell of course only now because we did not know that the
>> RTFbox was the bottleneck.
> I'm not convinced the bottleneck is the RTF box per se! Yes the
> ListView is faster then the RTF Box, but that does not prove that the
> RTFBox is the bottle neck!
>
> The bottleneck may be the interop marshalling from .NET world to the
> Win32 RTF Textbox world. In which case both the RTFBox & the ListView
> will have a problem as both are based on "native" Win32 controls.
>
> The bottleneck may be the GC!
>
> The bottleneck may actually be the way Charles' program is interacting
> with memory.
>
> The bottleneck may be some unrelated program that happens to be
> running.
>
> The bottleneck may be some unforseen disk access, such as page
> swapping.
>
> The bottleneck may be any number of other things...
>
> Hence my suggestion to use CLR Profiler & other tools to try to
> accurately identify where specifically the bottle neck is.
>
> Or at the very least two methods & see which is faster. However I have
> seen where one method may be faster for small number and/or size of
> objects, suddenly becomes painfully slow for large number and/or size
> of objects...
>
> As Charles initially stated "The problem I have is that sometimes, for
> no apparent reason, a step in my process takes an inordinate amount of
> time, e.g 2.5 seconds instead of perhaps 300 ms." The "sometimes, for
> no apparent reason" would suggest to me that it is not specifically
> the RTF or the BeginInvoke, although it could be.
>
> In other words BeginInvoke & the RTF Box are both still suspects,
> however the jury (CLR Profiler) has not convicted them of any crime.
>
> Just a thought
> Jay
>
> "Cor Ligthert" <no************@planet.nl> wrote in message
> news:en**************@TK2MSFTNGP14.phx.gbl...
>> Charles,
>>
>> It has not to do with the way I told or others told
>>
>> This has to do with the design.
>>
>> When you use 3 instead of 2 tiers than you can let your loading of
>> your RTFBox go smooth without any waiting in a seperated thread.
>> Collect the information for that in another tier as well in a
>> seperated thread. And let the worker tiers get the information for
>> the last in as well seperated threads.
>>
>> This I can tell of course only now because we did not know that the
>> RTFbox was the bottleneck.
>>
>> Describes this better what I mean?
>>
>> Cor
>>
>
>



Nov 22 '05 #80
Charles,
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|
I wasn't aware that I was. Surely the illness is displaying too much data,


I thought the illness was that your task takes too long:

<quote>
The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms.
</quote>

Of course the fact your task takes too long may be a symptom of a different
problem... such as the alleged display problem.

I have not seen anything that definitely suggests to me the problem is the
display itself. Although I will admit it is one of my prime candidates ;-)

Quirky little chicken & egg problem isn't it ;-)

Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
Jay
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|


I wasn't aware that I was. Surely the illness is displaying too much data,
which I am addressing. I was just bemoaning the fact that the original
solution had its benefits, so now I have to regain those benefits by some
other means.
It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...


I don't actually want to go down this route. I fancy someone somewhere
must have done this already. I just need to find it! You have prompted me
to try html though. That could be quicker and, as I know html, easier too.
It doesn't have to be rtf. The main requirement is that however I save the
data, it can be displayed outside my app, but retaining the colour coding.

Charles

<<snip>>
Nov 22 '05 #81
CMM
His foremost problem is definately the RtfTextBox. Out of curiosity, I did a
simple test that appended several hundred lines to the control... after two
minutes the loop still wasn't done and I just stopped it. I wasn't even
formatting the text (color, font, etc) after appending it. I even used
BeginUpdate and stuff to keep it from redrawing until the loop was done.

Just like the TreeView control, the RtfTextBox seems like a very slooowww
control for whatever reason and certainly not usable for *frequent updates.*

P.S. Charles mentioned something about HTML. There is no intrinsic .NET
control to display HTML. You'd need to use WebBrowser ActiveX control...
chances are that it will be as slow as the RtfTextBox. I just can't see why
you can't write the control yourself... it seems like such a simple set of
requirements.

1) Keep statuses in a collection.
2) Tie the collection to a VScrollbar
3) Draw the items on a UserControl surface's OnPaint using DrawString.

*Pseudocode*:
Sub OnPaint
posY = VScrollBar1.Value
Do Until posY > Me.ClientRectangle.Bottom or posY > Items.Count
DrawString(Items.Item(posY)
posY += 1
Loop
End Sub

You get the idea. The only tricky part is supporting user "selection" so
that they can copy stuff to the clipboard. But even that is possible with a
little more work.
"Jay B. Harlow [MVP - Outlook]" wrote:
Charles,
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|


I wasn't aware that I was. Surely the illness is displaying too much data,


I thought the illness was that your task takes too long:

<quote>
The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms.
</quote>

Of course the fact your task takes too long may be a symptom of a different
problem... such as the alleged display problem.

I have not seen anything that definitely suggests to me the problem is the
display itself. Although I will admit it is one of my prime candidates ;-)

Quirky little chicken & egg problem isn't it ;-)

Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...

Jay
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|


I wasn't aware that I was. Surely the illness is displaying too much data,
which I am addressing. I was just bemoaning the fact that the original
solution had its benefits, so now I have to regain those benefits by some
other means.
It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...


I don't actually want to go down this route. I fancy someone somewhere
must have done this already. I just need to find it! You have prompted me
to try html though. That could be quicker and, as I know html, easier too.
It doesn't have to be rtf. The main requirement is that however I save the
data, it can be displayed outside my app, but retaining the colour coding.

Charles

<<snip>>

Nov 22 '05 #82
CMM,
P.S. Charles mentioned something about HTML. There is no intrinsic .NET
control to display HTML. You'd need to use WebBrowser ActiveX control...
chances are that it will be as slow as the RtfTextBox. I just can't see
why
you can't write the control yourself... it seems like such a simple set of
requirements


There is probably noboby (from the actives in these both newsgroups) who
knows more from the Webbrowser than Charles.

:-)

Cor
Nov 22 '05 #83
Jay
I thought the illness was that your task takes too long:
I wasn't going back that far but, yes, you are right. The difficulty in
diagnosing that part of the problem is infrequent access to the target
equipment. I can't satisfactorily replicate the conditions without it.

I am not able yet to blame it all on the RTB, but when I stopped writing
messages to it every 50 ms I stopped overrunning my time window. I can't
remember without looking back over this thread whether I explained that I
have a couple of seconds in which to complete a process There might be 20
messages that I display in that time. When I display them in a RTB my
background process can occasionally take more than 2 seconds. If I don't
display them then it never seems to take longer than 800 ms, say. This is
odd because I use BeginInvoke on the RTB, so I would expect the display
process not to hold up my background task. But it seems to sometimes.

What I haven't been able to test yet is whether replacing the RTB with a
ListView overcomes the problem. It is certainly very much quicker, but if
BeginInvoke were doing its job then it wouldn't matter.

Anyway, that is why I am now considering outputting less data. I consider
that it may be too difficult/time consuming to actually fix the problem, so
I am looking to change the conditions sufficiently so that the problem goes
away. Not very scientific, I know, but just a smattering of pragmatism.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:up*************@tk2msftngp13.phx.gbl... Charles,
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|


I wasn't aware that I was. Surely the illness is displaying too much
data,


I thought the illness was that your task takes too long:

<quote>
The problem I have is that sometimes, for no apparent reason, a step in my
process takes an inordinate amount of time, e.g 2.5 seconds instead of
perhaps 300 ms.
</quote>

Of course the fact your task takes too long may be a symptom of a
different problem... such as the alleged display problem.

I have not seen anything that definitely suggests to me the problem is the
display itself. Although I will admit it is one of my prime candidates ;-)

Quirky little chicken & egg problem isn't it ;-)

Just a thought
Jay

"Charles Law" <bl***@nowhere.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...

Jay
I'm concerned you are treating symptoms rather then treating the illness
itself. :-|


I wasn't aware that I was. Surely the illness is displaying too much
data, which I am addressing. I was just bemoaning the fact that the
original solution had its benefits, so now I have to regain those
benefits by some other means.
It should not be that hard to create an RtfTextWriter class (ala
XmlTextWriter or HtmlTextWriter classes). That would encapsulate writing
formatted RTF to a text file (Stream). I would expect creating an
RtfTextReader would be more work...


I don't actually want to go down this route. I fancy someone somewhere
must have done this already. I just need to find it! You have prompted me
to try html though. That could be quicker and, as I know html, easier
too. It doesn't have to be rtf. The main requirement is that however I
save the data, it can be displayed outside my app, but retaining the
colour coding.

Charles

<<snip>>

Nov 22 '05 #84

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.