Windows are rendered in the plugin

I have a dll that runs as an out-of-process plugin in another application.

When the main application calls my plugin, my code runs on a thread pool thread (I think) inside my plugins appdomain. This is the MTA thread.

My question is what is the correct way to show a message / dialog in my plugin?

Most of the answers I've found only say that the dialog should open on a "GUI thread", but I don't have a GUI thread in my application. Tried searching for a GUI thread definition but couldn't find anything. Some clues say this is the thread it is running on Application.Run

.

I tried to just create a STA thread and open a dialog / dialog there. It looks like it works most of the time, but sometimes I get weird 100% CPU usage inside the method ShowDialog

.

Should I start a message loop from Application.Run

in my own application? Should it only run during the callback or is it expensive to create / break, so I have to create it on startup and run it all the time?

(I have access to the main application window handle which I am using as parent / owner)

+3


source to share


1 answer


Try using Win API NativeMethods:

/// Direct Task Dialog call. [DllImport("comctl32.dll", CharSet = CharSet.Unicode, EntryPoint = "TaskDialog")] public static extern int TaskDialog(IntPtr hWndParent, IntPtr hInstance, string pszWindowTitle, string pszMainInstruction, string pszContent, int dwCommonButtons, IntPtr pszIcon, out int pnButton);



You can find a good example here: https://code.google.com/p/cassini/

+1


source







All Articles