adrianm
adrianm

Reputation: 14726

Windows forms in a plugin

I got a dll which is running as an out-of-process plugin in another application.

When the main application calls into my plugin my code runs in a thread-pool thread (I think) inside my plugins's appdomain. It is a MTA thread.

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

Most answers I have found only says the dialog should open in "the GUI thread" but I don't have a GUI-thread in my appdomain! Tried searching for a definition of GUI-thread but could not find anything. Some hints says it is the thread where Application.Run is executed.

What I have tried is to just create a STA-thread and open the messagebox/dialog there. It seems to work most of the time but occationally I get a strange 100% CPU usage inside the ShowDialog method.

Should I start a message loop with Application.Run in my own appdomain? Should it run just during the callback or is it expensive to create/teardown so I should create it at start and have it running all the time?

(I have access to the main application's window handle which I use as parent/owner)

Upvotes: 3

Views: 442

Answers (1)

gogosweb
gogosweb

Reputation: 101

Try to use 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 good using example here: https://code.google.com/p/cassini/

Upvotes: 1

Related Questions