2

I have a stored procedure which runs for 8 mins, need to trigger the SP which will update records in multiple tables from WPF application, but thats timing out as the SP runs for 8 minutes, So planning to implement Asynchronous call to the SP like, just triggering the SP to run, which eventually when completed updates the records in 8 minutes. I know that SP can be optimized, but just want to know if at all there is a feature to trigger and dont wait for the result.

Thanks in Advance ..

1 Answer 1

1

Its best to perform the long-running work (e.g. communication with server/DB) on the background thread and once the thread completes, have the UI thread update the UI.

With BackgroundWorker:

Easy to implement background threading.

var worker = new BackgroundWorker();

worker.DoWork += (sender, args) =>
{
    // long running work
};

worker.RunWorkerCompleted += (sender, args) =>
{
    // Update UI
};

worker.RunWorkerAsync();

async/await pattern:

The action following the the await keyword, which returns a Task, will be run on a background thread and the rest of the method will act as a callback.

public async void DoWork()
{
    // Do long running task
    var data = await Task.Run(() => new object());

    // Update UI here
}

TaskFactory:

Task.Factory.StartNew(() => new Object()).ContinueWith(task => MessageBox.Show(task.Result.ToString()), TaskScheduler.FromCurrentSynchronizationContext());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.