There is a way to change wpf components in another thread with ironpython 2.7?
Question: So, I'm trying to make some function run without freezing the GUI. There is
some way to change the text from a textblock in another thread? For example:

    
    
    import wpf
    import thread
    
    from System.Windows import Application, Window
    
    class MyWindow(Window):
        def __init__(self):
            wpf.LoadComponent(self, 'WpfApplication2.xaml')
    
        def setText(self):
            self.textblock.Text = "Hiiii!"
    
        def button_Click(self, sender, e):
            thread.start_new_thread(self.setText,())
    
    if __name__ == '__main__':
        Application().Run(MyWindow())
    

and my wpf:

    
    
    <Window 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           Title="WpfApplication2" Height="300" Width="300"> 
           <Grid>
               <TextBlock x:Name="textblock" Text="Oi" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" FontSize="32" TextAlignment="Center" />
            <Button x:Name="button" Content="Change" HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="100" Height="50" Click="button_Click"/>
    
        </Grid>
    </Window> 
    

I can't in any way that I try to change the text block in another thread.
There is no way to make, for example, a infinite while loop to update data,
without freezing the GUI?


Answer: I have no clue about python but I use C#. I will tell you how I do it in C#
and I'm sure it will hit the bell in your head :)

The thing is that GUI runs in the main thread, so if something else is running
in the main thread it will freeze the UI. In the other hand, things that don't
run in the main thread, cannot affect the UI which is kind of annoying but
makes all the sense.

The solution is to use threads. In C# I recommend the usage of
BackgroundWorker but I'm sure you have thread facilities in python as well.

then you can use events in your thread to tell the UI about updates in the
status (for loading bars for instance) or when it is finished. Catch those
events from the GUI thread (the main one) and update any component as needed.

The other approach is to access the main thread from the secondary thread. For
doing this in C# you use the expression:

    
    
    Dispatcher.Invoke((Action) delegate 
    {
        here your code accessing controls in the UI as if you
        where in the main thread
    }
    

Hope this helps you finding your way.

