A part of my Delphi application accesses information from another program. Because it can take some time to execute, and sometimes the other program may be unresponsive, I run that part of my code in a separate thread.
To keep my users informed of the progress of the background thread, I execute a TaskDialog after I start the thread. I pass a pointer to the TaskDialog to my thread so that the thread can synchronize with the TaskDialog to update it as the thread progresses. When the thread finishes, I send a close message to the TaskDialog using PostMessage(CurrentTaskDialog.Handle, WM_CLOSE, 0, 0);
Everything is working so far, but I want to cancel the process if the user clicks the Cancel button on the TaskDialog (it is the only button on the TaskDialog). I cannot figure-out how to do it. No matter whether the user clicks the button or if the TaskDialog receives the close message, the ModalResult
is always mrCancel
. I have tried assigning a different ModalResult
in the thread, but it still evaluates as mrCancel
.
Is there some way to accomplish this?