Thanks. I've added a call to Application.Run() and also this: ExeThread.SetApartmentState(ApartmentState.STA);
Seems to be happy now! Andy On 2/25/2015 8:47 PM, Andrew Graham wrote: > Not really strange, expected behaviour in fact. The Form is drawn OK but > there is no message loop running on the thread to pump messages to it so > it will be unresponsive and sit there until the thread exits. A modal > dialog, or Form shown modally, tries to pump the message queue itself, > that is how it acheives modality, and as my previous email to you > stated, as there is no message loop on your thread for it to pump so > that is probably why it hangs. > > Regards > > Andy graham > > -----Original Message----- From: Andrew Ayre > Sent: Wednesday, February 25, 2015 4:41 PM > To: ironpython-users@python.org > Subject: Re: [Ironpython-users] ShowDialog Hangs > > Thanks for the responses. Strangely the following script works: > > import clr > import time > clr.AddReference("System.Windows.Forms") > from System.Windows.Forms import OpenFileDialog, DialogResult, Form > F = Form() > F.Show() > time.sleep(5) > > This displays a form and then closes it when the script ends after five > seconds. > > However simply swapping F.Show for OpenFileDialog().ShowDialog() causes > the script to hang. > > I will check the suggestions made, but I wondered if this behavior with > the form gives anyone some additional clues. > > Thanks, Andy > > On 2/25/2015 2:50 PM, Slide wrote: >> You need to make sure the thread was started as an STAThread I believe, >> otherwise the common windows controls (OpenFileDialog being one of them) >> won't work correctly. >> >> On Wed Feb 25 2015 at 2:02:32 AM Andrew Ayre <a...@britishideas.com >> <mailto:a...@britishideas.com>> wrote: >> >> I am sure I am making a silly mistake somewhere. >> >> I have IronPython embedded in my C# WinForms application. >> >> The interpreter is running in a thread that has been created for it. >> I.e. not the UI thread. >> >> Everything works fine until the call to Dialog.ShowDialog, at which >> point execution of IronPython hangs and no dialog appears. >> >> I'm guessing that this is because the interpreter is not running >> in the >> UI thread (which I don't want to do because sometimes scripts can >> take a >> long time to execute, depending on what they are doing). >> >> This is my first attempt using WinForms from scripting in my >> application. >> >> Any hints or suggestions on how I can debug this, synchronize with >> the >> UI thread or something else? >> >> Thanks! Andy >> >> import clr >> clr.AddReference("System.__Windows.Forms") >> from System.Windows.Forms import OpenFileDialog, DialogResult >> >> Dialog = OpenFileDialog() >> Dialog.ShowDialog() >> >> -- >> Andy >> PGP Key ID: 0xDC1B5864 >> _________________________________________________ >> Ironpython-users mailing list >> Ironpython-users@python.org <mailto:Ironpython-users@python.org> >> https://mail.python.org/__mailman/listinfo/ironpython-__users >> <https://mail.python.org/mailman/listinfo/ironpython-users> >> > -- Andy PGP Key ID: 0xDC1B5864 _______________________________________________ Ironpython-users mailing list Ironpython-users@python.org https://mail.python.org/mailman/listinfo/ironpython-users