Click here to Skip to main content
15,032,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys,
I created a simple desktop form to import some data from dataGridView to sql server database, and to make it easy I put a progressBar on my form, then I started two threads on for the progressBar and other one for my save method( ),then I started to import about 800 records.
the problem is when I start to run this form in the normal way, it took about 3 minutes to save this data, but when I minimize the form while it working, it took like 20 seconds maximum to save my data.
so in the normal form mode it's so slow to save my data,but when the form is not the active form or minimized it become very fast.

code sample:
System.Threading.Thread t1;
System.Threading.Thread proth;
int thcount = 0;
under the button:
void btnExport_Click(object sender, EventArgs e)
       thcount = 0;
       progressBar1.Value = 0;
       progressBar1.Maximum = grdList.Rows.Count;
//save method
       t1 = new System.Threading.Thread(Save);
//progress bar method
       proth = new Thread(startProgress);

please help

thanks for every one
Updated 24-Dec-10 0:58am
Smithers-Jones 24-Dec-10 6:59am
added pre-tags.

1 solution

You only need one thread. This thread would save a record and then report progress back to the form which would update the progress bar.

In fact, I think you can make it easier on yourself by creating a BackgroundWorker object instead of a thread because it already has the ability to a) send progress events, and b) can be easily canceled.

Here's a link that describes how to update the UI from a thread (including BackgroundWorker objects):[^]

The difference in processing time you're seeings is because the thread doesn't have to update the UI when the window is minimized.

EDIT ======================

If you're having performance issues, you're going to have to just muscle through it and use the tools on hand to find/mitigate the choke points. Try using Trace statements and just let the program run. The trace statements will send text to the output window in Visual Studio, and you can observe what's happening and when. This will slow down your process even more, but at least you'll be able to watch what's happening.

#realJSOP 24-Dec-10 8:24am
From the OP: thank you for your answer,

actually I tried to use the background event, but it gave me the same performance,
my form is working good, but my problem is about it's performance,so when the window state is set to normal state the form is too slow ,but when the window state is set to minimized state, it become very fast.

If u give me your mail so I'll send you a print-screen.
Manfred Rudolf Bihy 24-Dec-10 17:28pm
Good answer! 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900