Search code examples
wpfuser-interfaceasynchronouscommandexecution

Is there a best way to manage WPF UI when using Asynchronous execution commands?


is there a best way to manage a form in WPF application which has asynchronous execution commands?

1) Suppose you have a form where user enters all his data and clicks on Ok button to save changes.

2) Your WPF app starts an asynchronous method to record those data.

3) Now suppose the database server is down, and the operation is taking about 15 seconds to get finished. At this time, user has already closed the WPF form (he did not wait for the transaction to be finished).

So that's my question: how could you control when to let user close or not the form?

thank you


Solution

  • Easy answer...don't let the user close the form until the operation is complete.

    You can accomplish this with a Modal infinitely scrolling progress bar. It provides feedback to the user that your application is doing something...but doesn't let the user close the window they were working in.

    This allows you to run your code outside the UI thread and then when your code completes (either finishes or errors out) you can provide feedback to the user about what happened (either success or something happened and they need to save again).