[MonoDevelop] Process with Mono

guybrush.d thera at interfree.it
Tue Dec 7 19:58:53 EST 2010


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 frmAvviaInstallazione() : 
	base(Gtk.WindowType.Toplevel)
{
		this.Build();
		
                this.DeleteEvent += delete_event;
              	

		Thread thr = new Thread (new ThreadStart (ThreadRoutine));
                thr.Start ();
		Thread.Sleep (100);
				
		Thread thr1 = new Thread (new ThreadStart (LeggiOutput));
                thr1.Start ();
            
                if (sortProcess.HasExited)
		{
		     thr.Abort();
		     thr1.Abort();
		     sortProcess.Close();
		}
}

.....
....
public void ThreadRoutine ()
{
	AsyncProcess ();
		
}

public void AsyncProcess()
{
	sortProcess.StartInfo.FileName = @"/usr/sbin/slapt-get"; //command 
        sortProcess.StartInfo.Arguments = " --list"; 	//no need of root
privileges

        // Set UseShellExecute to false for redirection.
        sortProcess.StartInfo.UseShellExecute = false;
	sortProcess.StartInfo.RedirectStandardOutput = true;
            
	sortProcess.StartInfo.CreateNoWindow = true;
            
         // Start the process.
         sortProcess.Start();
         sortProcess.WaitForExit();
		
}
		
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.
-- 
View this message in context: http://mono.1490590.n4.nabble.com/Process-with-Mono-tp3042268p3077519.html
Sent from the Mono - MonoDevelop IDE mailing list archive at Nabble.com.


More information about the Monodevelop-list mailing list