I have a stored procedure that when called does a large amount of processing. Various parts of the stored procedure are wrapped in their own transactions but, the entire proc. does not run in a transaction as this would cause unnecessary blocking and harm performance. The problem I have is that if a user closes the user interface after the proc. has started and before it ends, the connection closes and the proc. stops executing.
Is there any way to do this asynchronously or in another process that won’t abort if the user interface application is closed during processing.
Look at the C# Task Parallel Library.
You can create a task which is very simple. For example…
This will run the code wrapped in the task in parallel with the main thread. If you wish to check the task is complete you can use
This method avoided altering the stored procedure and allows C# to handle the performance.
Edit:-
And to avoid the main thread finishing first add
This will sleep the main thread until the task is complete.