[MonoDevelop] Process with Mono

Adam Tauno Williams awilliam at whitemice.org
Wed Dec 8 06:17:00 EST 2010


> On Wed, Dec 8, 2010 at 2:58 AM, guybrush.d <thera at interfree.it> wrote:
> Ciao.
> ok guys i made a step forward (finally!) i'm able to redirect the
> standard output to the textview
> widget of my app using two threads, after launching the
> command(through the process method)
> my textview begins to fill with the output, but after some lines (the
> number is different each time),
> the program crashes! Here is the code i'm using:
>         public void AsyncProcess()
>         {
>         void LeggiOutput()
>         {
>                while (!sortProcess.HasExited)
>                {
>                        string testo =
>         sortProcess.StandardOutput.ReadLine() +
>         Environment.NewLine;
>                        textview1.Buffer.Text += testo;
>         
>                        Thread.Sleep (100);
>         
>                }
>         }
>         
>         Any help is VERY welcome,, thanks in advance, ciao.

You are modifying the UI ["textview1.Buffer.Text += testo;"] from
outside the main thread - only the main thread can modify the GUI.  This
is documented; making GTK calls from a secondary thread is guaranteed to
crash your application.

see <http://www.mono-project.com/Responsive_Applications>


A simple 

Gtk.Application.Invoke (delegate {
             textview1.Buffer.Text += testo;
        });

will probably solve your problem.   This pushes that code as an event
into the run-loop of the main thread.




More information about the Monodevelop-list mailing list