tags:

views:

36

answers:

2

I have to execute a stored procedure. When I execute that, I have to keep on check (ping) whether that execution is completed or not. The I will update a label.

Do we have any way in c# to do that?

A: 

Call the stored procedure asynchronously, and have the callback update your label.

Here's an article about it

Dan
Can you post the relevant code snippet? Linking to articles that require registration in order to read is very annoying. If I don't have an account to this site I have to create a new one, probably validate my email address, be bombarded by spam later, lose from my precious time, etc... you get the point.
Darin Dimitrov
No registration required from what I can tell. There are many articles on Asynchronous database calls. The only trap you may run into is that when your callback occurs, you'll be on a separate thread than what your UI was on, and you'll have a Cross-Thread operation not valid error. Here's how to solve that one (guaranteed no registration, and has working samples, no files to download): http://codingcramp.blogspot.com/2010/05/c-cross-thread-operation-not-valid.html
Dan
@Dan, maybe that's because you are already registered and signed in on this site. It asks me for registration.
Darin Dimitrov
A: 

SqlCommand.ExecuteNonQuery() returns an int when it is complete. If you're doing this "in line" then ExecuteNonQuery() won't hand control to the next statement until the stored procedure is complete.

If you're doing this in a background thread somehow (threading / asynchronous call) the code within your background thread will still not hand control to the next statement until the proc ends (okay, not exactly, Asynchronous uses IAsynchCallback- I'm trying to be general here) so the AsynchCallBack or the Thread.Exit() should be able to tell your main thread that the procedure is complete.

AllenG