Performance issues with WinForm controls in a multithreaded environment

G

Guest

Thanks for reading this post fellow listers. I am in a state of utter confusion and I hope that someone might be able to help me. Let me give some background on the architecture of the code to help with your understanding. I have an importation framework that is driven from xml config files. It maps a given field position to a strored procedure parameter. This is a distruted application which is using remoting. I have a ThreadHelper class that has a function that executes the code to call cycle through the records in a tab delimited text file, checks them for duplication, and then does an call to the remoting server to save a single record. During the initial parsing and the subsequent import operation the ThreadHelper class is throwing events as to number of errors caught, current record number about 17 other events. I have a control that allows me to fire off this thread helper class on it's own thread and captures the events and displays things like # records parsed, # errors during parse, # records to import, current record being imported, errors encountered during import, estimated time to completion, # of records per second being imported, average # of records per second imported and quite a few others. It also has a progress bar so the user can visually see how far along in the import process he/she is
Okay here comes the interesting and perplexing part. The control and framework work fine. When I fire off the import process with the application in focus the control is reporting between 6-9 records per second. As soon as I switch focus to another application the number of records per second being processed jumps up to between 25 - 30 records per second. That is a head scratcher to me. As soon as I bring the app back into focus the records per seconds drop back down to betweent 6-9, as soon as I move focus to another application it jumps back up to between 25 - 30. I am baffled. Would anyone know even where to start in looking at this issue. Any help would be *greatly* appreciated

Sincerely

John Sheppar
Missouri Botanical Gardens
 
J

Jon Skeet [C# MVP]

John Sheppard said:
Okay here comes the interesting and perplexing part. The control and
framework work fine. When I fire off the import process with the
application in focus the control is reporting between 6-9 records per
second. As soon as I switch focus to another application the number of
records per second being processed jumps up to between 25 - 30 records
per second. That is a head scratcher to me. As soon as I bring the app
back into focus the records per seconds drop back down to betweent
6-9, as soon as I move focus to another application it jumps back up
to between 25 - 30. I am baffled. Would anyone know even where to
start in looking at this issue. Any help would be *greatly*
appreciated.

How much are you doing in the UI thread? Are you doing something on
every mouse movement etc? What happens if you turn off the progress bar
etc, or at least limit it to only report progress every (say) 20
records?
 
G

Guest

Jon Skeet wrote
Jon
Thanks for the reply. I am not doing to much in the UI thread. The only things I am doing is updating some labels and calling the step on the progress bar in response to events from the ImportThreadHelper object. Plus I am keeping some running totals from the events. Oh and I have a timer that fires every second so I can display averages from those same totals. The really strange thing to me is when the application is out of focus the speed picks up 50 - 70% but when the app does have focus it drops off dramatically. I am working on putting the control on it's own form now and firing that off and let it run out of focus to see if it's when the entire application comes into focus or just that control
I will also turn off the progress bar to see, but I somehow don't think thats it because, like I said, when the window doesn't have focus the control is updating just fine including the progress bar

Thanks

John Sheppard
 
G

Guest

Listers,
Okay even more strangeness. I have moved the control to its own form that is popped up non-modally from the main application. I have limited to updating statistics on the control to once a second every time the timer control fires. Now the behavior I am observing is it runs at the expected 25-35 records per second when it initally has the focus and is started. If I switch the focus to another application it continues to run at the same speed. Now when I go back to the Import form the speed drops back down to between 6-8 records per second. If I switch to another application it jumps back up. Here is another interesting thing I noticed. If I click my mouse down and hold it on any part of the application, doesn't matter which part, the speed jumps back up to the 25-35 records per second. Wowsers this is truly a interesting problem. I can't wait to get to the root cause so that I can see what is causing this bizarre behavior. As always, any insight would be greatly appreciated

Thanks

John Sheppar
Missouri Botanical Gardens
 
J

Jon Skeet [C# MVP]

John Sheppard said:
Okay even more strangeness. I have moved the control to its own form
that is popped up non-modally from the main application. I have
limited to updating statistics on the control to once a second every
time the timer control fires. Now the behavior I am observing is it
runs at the expected 25-35 records per second when it initally has the
focus and is started. If I switch the focus to another application it
continues to run at the same speed. Now when I go back to the Import
form the speed drops back down to between 6-8 records per second. If I
switch to another application it jumps back up. Here is another
interesting thing I noticed. If I click my mouse down and hold it on
any part of the application, doesn't matter which part, the speed
jumps back up to the 25-35 records per second. Wowsers this is truly a
interesting problem. I can't wait to get to the root cause so that I
can see what is causing this bizarre behavior. As always, any insight
would be greatly appreciated.

This sounds fascinating - I'd love to have a look. Do you have enough
time to create a pared down version of the app which displays the same
characteristics but in a simplified app which you're happy to share?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top