August 7th, 2024

How do I know when the user has finished interacting with the Accounts­Settings­Pane?

The Accounts­Settings­Pane.Show method shows the accounts settings pane and returns immediately. How do you know when the user has closed the pane?

If the user selects one of your commands, you get a notification in the form of the Invoked event on that command. But what if the user closes the pane without selecting anything?

Instead of using the Accounts­Settings­Pane.Show method, use the Accounts­Settings­Pane.Show­Manage­Accounts­Async method. The Show­Manage­Accounts­Async method does the same thing as Accounts­Settings­Pane.Show, except that it returns an IAsync­Action which completes when the pane is closed (for whatever reason).

(Dirty secret: Really, it’s the other way around. The Accounts­Settings­Pane.Show method just calls the Accounts­Settings­Pane.Show­Manage­Accounts­Async method. and throws away the IAsyncAction.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

1 comment

Discussion is closed. Login to edit/delete existing comments.

Newest
Newest
Popular
Oldest
  • Kevin Norris

    Note that the more general version of this pattern (“I want to open [something], let the user interact with it for a while, and wait for them to close it”) is questionable at best, at least in the case where [something] involves Explorer or any web browser. The user might navigate away or start doing something else, and then, hours later, alt-tab back to your window only to find it frozen because you’re still waiting for them to close the window (that they forgot you opened). Worse, the program might just forward to its “main” instance and terminate immediately. Raymond previously discussed this in the context of Explorer in 2011.

Feedback