c# Gui Freeze when waiting for Data

  • Thread starter Thread starter Lam
  • Start date Start date
L

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
 
Shift the data access into a different thread.

If you're using .NET 2.0, see the BackgroundWorker class.
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
 
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.
 
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

Shift the data access into a different thread.

If you're using .NET 2.0, see the BackgroundWorker class.
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
 
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

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.
 

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

Back
Top