[Ironpython-users] ShowDialog Hangs

Andrew Ayre andy at britishideas.com
Wed Feb 25 17:41:46 CET 2015


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 <andy at britishideas.com
> <mailto:andy at 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 at python.org <mailto:Ironpython-users at python.org>
>     https://mail.python.org/__mailman/listinfo/ironpython-__users
>     <https://mail.python.org/mailman/listinfo/ironpython-users>
> 

-- 
Andy
PGP Key ID: 0xDC1B5864


More information about the Ironpython-users mailing list