Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Stopping a thread "during" a statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oliver J. Hanau - 27 Mar 2006 18:08 GMT
I need to call a time-consuming stored procedure on an SQL Server. This
means that a single SqlCommand.ExecuteNonQuery() call might take a
couple of hours. That's why I put it into a subthread, so I can at
least show the clock running.

I would very much like to allow the user to stop this operation, but
calling Thread.Abort() only sets the ThreadState to AbortRequested.
Only when the ExecuteNonQuery() call then returns, a
ThreadAbortException is finally encountered, but this could happen a
couple of hours after clicking "Cancel", so it's not what I need.

When I debug this in VS 2005, it considers the application to be
running because of this thread until I press "Stop Debugging",
whereupon the thread is stopped immediately. So, VS 2005 is able to
terminate this process during the call. Does it do this via WinAPI
calls the way the Task Manager would (I assume), or is there a less
messy way in .NET?

Thanks
Oliver
Larry Lard - 28 Mar 2006 11:59 GMT
> I need to call a time-consuming stored procedure on an SQL Server. This
> means that a single SqlCommand.ExecuteNonQuery() call might take a
[quoted text clipped - 6 lines]
> ThreadAbortException is finally encountered, but this could happen a
> couple of hours after clicking "Cancel", so it's not what I need.

SqlCommand.Cancel any use here?

Signature

Larry Lard
Replies to group please

Oliver J. Hanau - 29 Mar 2006 18:14 GMT
> SqlCommand.Cancel any use here?

Works perfectly, thanks. I didn't think that the solution would be in
the *other* thread.

Oliver.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.