views:

29

answers:

1

Im trying to launch a dialog by invoking several methods from a windows forms assembly. My app is a console app. All the execution logic goes well and without exceptions, but the window is not launched. Is it a known issue that you cant launch a windows form from a console app?

+1  A: 

well, yes. You have to have a Windows message loop for this to work. If you create a Forms application from scratch, you'll see the Program.cs module created with ... Application.Run(new YourMainForm()) in it. Run is basically the message pump - having that is pretty much a requirement for forms to work.

500 - Internal Server Error
Is there a way to simulate this Run with Dispatchers or something else?
kateroh
Yes, I'm sure there's a way, but I myself haven't done anything like that. As opposed to WPF apps, Windows Forms apps are essentially traditional WIN32 GUI applications (they use traditional window messages, handles, and so on to do their stuff) - they just use managed code. In WIN32, to do something like this, you could fire up your own thread and call GetMessage, DispatchMessage, and friends, to have the message for your dynamically created window processed. This *should* work with Forms apps as well, but there might be caveats.
500 - Internal Server Error
Thanks for explaining this! This is actually a WPF app/form that i need to create within the console app. Any advice on how this can be accomplished with a WPF app?
kateroh
I'm not sure this is possible, but that could just be lack of knowledge on my part. I would post a message with a title along the lines of "WPF form in a console app?" to see if anyone bites.
500 - Internal Server Error
Opened a new thread: http://stackoverflow.com/questions/3857828/wpf-form-in-a-console-app. Thank you for your help!
kateroh