Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've made my own custom Task Dialog window in WPF. I wanted it to follow the style of my application, and I have some custom content to place on it, so I prefer not using the win32 task dialog.

My application uses asynchronous tasks (async/await) to load data from the database. If there's an error/exception while loading data, the ui thread will show a (custom) TaskDialog with error information.

The win32 task dialog will show one instance of itself, and other pending TaskDialogs to show will only show up after the first has returned (or actually it seems to block awaited task continuations) The problem is that my custom task dialog is showing multiple errors at the same time (from awaited tasks), showing up multiple times on the screen.

The way I understand the issue (and perhaps I'm wrong here) is that despite using ShowDialog(), my task dialog is running on the UI thread and pumping messages. Further synchronous main window code is not executing, but if a task finishes awaiting, it returns to the UI thread to execute, and assuming there was a data load error, another (custom) task dialog is shown:

1) Main window starts data loading in multiple awaited tasks
2) awaited task returns with error/exception
3) Custom task dialog window is shown with ShowDialog()
4) While custom task dialog still showing, another awaited task returns with an error as well
5) Continuation code executes on UI thread which is current showing task dialog
6) A second custom task dialog is shown over the first
etc

I really can't figure out how the Win32 taskdialog is blocking multiple calls to itself while keeping the UI thread alive. I've tried many different solutions, and nothing seems to work properly.

I realize I could make my task dialog async, use a semaphore and WaitAsync on it, but since my task dialog needs to return a TaskDialogResult, I'd need to await every call to my task dialog which would be way too many code changes.

I know I must be missing something here, anyone have any ideas on this?

What I have tried:

Making my task dialog call async, using a semaphore and WaitAsync on it works, but my task dialog needs to return a TaskDialog result, and so I'd have to await every call to it, unfortunately that's too many code changes.

I've tried running my task dialog in a separate thread and blocking the main UI thread until the task dialog returns. That does give me the desired effect, but blocking the main UI thread is causing issues elsewhere. This also doesn't seem like the proper way to do it.
Posted
Updated 21-Nov-17 19:12pm

1 solution

Use a Queue of Actions to buffer the Dialogs. Now you Dequeue & execute the actions (displaying of dialogues) in sequence, one at a time...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900