[IronPython] Hosting IronPython in Silverlight - background loading

Dave Curylo curylod at asme.org
Wed Aug 18 04:15:14 CEST 2010


Lukas,

I think the problem is the RunWorkerCompleted handler trying to update the
UI. Wrap calls from a background thread to update UI controls in something
like this so the Dispatcher updates any controls on the UI thread:

this.Dispatcher.BeginInvoke(() =>
    {
        this.textBlock1.Text = "IronPython loaded";
    });

Hope that helps.

-Dave

2010/8/17 Lukas Cenovsky <cenovsky at bakalari.cz>

>  Hi all,
> is it possible to load IronPython engine in the background thread in
> Silverlight?
>
> I tried to load it via BackgroundWorker:
>
> private void UserControl_Loaded(object sender, RoutedEventArgs ev)
> {
>    IPloader = new BackgroundWorker();
>    IPloader.DoWork += new DoWorkEventHandler((s, e) =>
>        {
>            runtime = DynamicEngine.CreateRuntime(true); // debug mode true
>            engine = runtime.GetEngine("python");
>        }
>    );
>    IPloader.RunWorkerCompleted += new RunWorkerCompletedEventHandler((s, e)
> =>
>    {
>        this.textBlock1.Text = "IronPython loaded";
>    }
>    );
>    IPloader.RunWorkerAsync();
> }
>
> It fails with the following exception:
>
> System.UnauthorizedAccessException was unhandled by user code
>  Message=Invalid cross-thread access.
>  StackTrace:
>       at MS.Internal.XcpImports.CheckThread()
>       at
> System.Windows.DependencyObject.GetValueInternal(DependencyProperty dp)
>       at System.Windows.Deployment.get_Parts()
>       at Microsoft.Scripting.Silverlight.DynamicAppManifest.AssemblyParts()
>       at Microsoft.Scripting.Silverlight.DynamicAppManifest..ctor()
>       at Microsoft.Scripting.Silverlight.DynamicEngine.CreateLangConfig()
>       at
> Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntimeSetup(Boolean
> debugMode)
>       at
> Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntime(Boolean
> debugMode)
>       at SLHosting.MainPage.<UserControl_Loaded>b__0(Object s,
> DoWorkEventArgs e)
>       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
>       at System.ComponentModel.BackgroundWorker.OnRun(Object argument)
>  InnerException:
>
> Thanks for any advice.
>
> --
> -- Lukáš
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100817/7c834bfb/attachment.html>


More information about the Ironpython-users mailing list