Issue in Creating a Threaded Modal Dialog sample?

25 views
Skip to first unread message

Terry Aney

unread,
May 4, 2024, 9:18:59 AM5/4/24
to Excel-DNA
Hi, after my long discussion about understanding the main UI thread context vs calculation thread(s) and ensuring proper use of `Thread.Run` and `QueueAsMacro`, there were situations I needed to display a Windows Form or MessageBox after starting a `Thread.Run` process.  Without doing anything, and simply displaying the form/dialog, Excel was *not* the owner, so I was going to follow the Creating a Threaded Modal Dialog sample.

What surprised me in the sample is that `Application.Hwnd` was access from within a `new Thread` delegate.  I would have expected all access to COM/UI objects to be required from *outside* of any new thread contexts?

I'd expect something along these lines:

Screenshot 2024-05-04 081335.png

Was it safe in the sample to access Application.Hwnd inside a new thread?
Reply all
Reply to author
Forward
0 new messages