views:

252

answers:

2

Hi guys

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

A: 

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).

Justin Niessner
I got to do this with my app! Thank you
Junior Mayhé
A: 

I would suggest that you disable the controls in the form when the asyncrhonous operation is started. This provides immediate feedback that the state of the form has changed. However, if the operation can be cancelled you should still allow the user to cancel/close the form. Closing the form should then cancel the operation.

If you expect the operation to take longer than a few seconds you should display some sort of feedback like a progress bar. Cancelling the operation should then be on a control visually associated with the progress bar.

Please don't show useless modal message boxes when the operation completes successfully. It is really annoying to not only have to wait for the operation but to have to click on "OK" when the operation is complete.

David Poll has created an Activity control for Silverlight that you might get some inspiration from.

Martin Liversage