By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,337 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,337 IT Pros & Developers. It's quick & easy.

c# Gui Freeze when waiting for Data

P: n/a
Lam
hi
I am writing a C# windows program which will get datatable from database through ODBC connection
then I show the the datatable on DataGridView.
The problem is that before the datatable get returned, the GUI freezes. I can't move it
On the program, I have different queries to get the different data back, some of them
get back withthin few seonds, some of them takes minutes to get the databack.is there anyway that
I can still be using the GUI (clicking on other control, enter some text. etc) while waiting for the data to show up?

Thanks
Mar 30 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You are invoking on the UI Thread. Invoke the database call on a worker
thread or a thread pool thread and then update the UI the moment you
get back the data from the database.

Mar 30 '06 #2

P: n/a
Shift the data access into a different thread.

If you're using .NET 2.0, see the BackgroundWorker class.
"Lam" <ja**********@hotmail.com> wrote in message news:eb**************@TK2MSFTNGP09.phx.gbl...
hi
I am writing a C# windows program which will get datatable from database through ODBC connection
then I show the the datatable on DataGridView.
The problem is that before the datatable get returned, the GUI freezes. I can't move it
On the program, I have different queries to get the different data back, some of them
get back withthin few seonds, some of them takes minutes to get the databack.is there anyway that
I can still be using the GUI (clicking on other control, enter some text. etc) while waiting for the data to show up?

Thanks
Mar 30 '06 #3

P: n/a
Lam

I have a class, (DBManager.cs) to call to access the database , then it returns the datatable to calling class
then the calling class bind the datatable to the DataGridView to show

you mean I have to create the thread to call DBManager?
can you show me a example?
Thanks a lot

"Brendan Green" <bg****@simtap.com.au> wrote in message news:uC**************@TK2MSFTNGP14.phx.gbl...
Shift the data access into a different thread.

If you're using .NET 2.0, see the BackgroundWorker class.
"Lam" <ja**********@hotmail.com> wrote in message news:eb**************@TK2MSFTNGP09.phx.gbl...
hi
I am writing a C# windows program which will get datatable from database through ODBC connection
then I show the the datatable on DataGridView.
The problem is that before the datatable get returned, the GUI freezes. I can't move it
On the program, I have different queries to get the different data back, some of them
get back withthin few seonds, some of them takes minutes to get the databack.is there anyway that
I can still be using the GUI (clicking on other control, enter some text. etc) while waiting for the data to show up?

Thanks
Mar 30 '06 #4

P: n/a
Lam
it sounds the solution for the problem
so should I create the thread pool or worker thread on seperate (individual class)?
or can I do it in the same class that create the form?
thanks

"Naveen" <na*********************@gmail.com> wrote in message news:11**********************@u72g2000cwu.googlegr oups.com...
You are invoking on the UI Thread. Invoke the database call on a worker
thread or a thread pool thread and then update the UI the moment you
get back the data from the database.

Mar 30 '06 #5

P: n/a
You should read up on delegates, BeginInvoke, EndInvoke, callback
delegates, and the like. Here is an article to get you started. The
code in the article is Visual Basic, but it's easy enough to understand
and translate the ideas into C#:

http://msdn.microsoft.com/msdnmag/is...asicInstincts/

Mar 30 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.