Using threading to call sql script

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

How can I use threading in my Windows Form to call a sql script that takes a
few seconds to run? When I click on a button, I'd like to call the SP,
display in my Form message a "Please wait" message, and then when the script
is done, fill the grids with this data.
I've read deveral articles on multithreading, but I really haven't found how
to "join" it to my gui thread once this new thread finishes.

Any help is appreciated. I'm using VS2005.

Thanks.
 
VMI said:
How can I use threading in my Windows Form to call a sql script that takes a
few seconds to run? When I click on a button, I'd like to call the SP,
display in my Form message a "Please wait" message, and then when the script
is done, fill the grids with this data.
I've read deveral articles on multithreading, but I really haven't found how
to "join" it to my gui thread once this new thread finishes.

I don't think you'll need Thread.Join here, but you'll almost certainly
want Control.Invoke or Control.BeginInvoke to "get back" onto the UI
thread so that you can update the UI from the right thread.

See http://pobox.com/~skeet/csharp/threads/winforms.shtml
 
There are various ways of accomplishing this task. Simple way is to
create a method that executes SQL task.

On your GUI thread, create a new thread and pass the above function as
ThreadStart. Start the new created thread. On your GUI thread you can
check the status of newly created thread on a timely fashion (for this
you can use a timer control). You can use the IsAlive property of thread.
If IsAlive returns false, that means thread have completed the execution
of method and result is ready to be displayed.
 
Back
Top