Laden...

Wann kehrt Process.Startinfo.Start() zurück

Erstellt von christof.k vor 19 Jahren Letzter Beitrag vor 19 Jahren 1.604 Views
C
christof.k Themenstarter:in
159 Beiträge seit 2005
vor 19 Jahren
Wann kehrt Process.Startinfo.Start() zurück

Hallo!

Ich implementiere gerade ein Programm, dass einen Command-Line compiler für jede Datei aufruft. Ich nutze dazu den folgenden Code:

Process localprocess = new Process();	
localprocess.StartInfo.UseShellExecute = false;
localprocess.StartInfo.RedirectStandardError = true;
localprocess.StartInfo.RedirectStandardOutput = true;  
localprocess.StartInfo.FileName   = File;
localprocess.StartInfo.Arguments  = Argument;
localprocess.Start();

Diese Zeilen laufen in einer Schleife um alle Dateien zu kompilieren.
Ich dachte bisher, dass ich damit zig Processe starte, und dass die Kontrolle sofort zum Programm zurückgegeben wird. Es scheint aber, dass erst nachdem der Prozess beendet wurde, die Kontrolle zurückgegeben wird.
Kann dies sein? Und wenn ja, wie schaffe ich es, mehrere parallele Prozesse zu starten?

Vielen Dank
Christof

P
939 Beiträge seit 2003
vor 19 Jahren

Sollte normalerweise so sein. Mit

Process localprocess = new Process();
localprocess.Start();

wird ein neues Process-Objekt erzeugt und ausgeführt. Es kann aber sein, dass das gestartete Programm nur eine Instanz zulässt und weitere Instanzen blockiert werden. Versuch doch mal den Compiler in zwei Kommandozeilen parallel zu starten.

Gruss
Pulpapex

1.371 Beiträge seit 2004
vor 19 Jahren

Du packst das ganze in eine Methode und startest es jeweils in einem neuen Thread,


private void BtnStart_Click(object sender, System.EventArgs e)
{
 Thread thread = new Thread(new ThreadStart(this.startProcess));
 thread.Start();
}


private void startProcess()
{
 Process localprocess = new Process();    
 localprocess.StartInfo.UseShellExecute = false;
 localprocess.StartInfo.RedirectStandardError = true;
 localprocess.StartInfo.RedirectStandardOutput = true;  
 localprocess.StartInfo.FileName   = File;
 localprocess.StartInfo.Arguments  = Argument;
 localprocess.Start();
}

==============================
Wenn ichs wüsst', würd' ich nicht fragen!!! 😁
==============================

P
939 Beiträge seit 2003
vor 19 Jahren

public bool Start()
Use this overload to start a process resource and associate it with the current Process component. The return value true indicates that a new process resource was started. If the process resource specified by the FileName member of the StartInfo property is already running on the computer, no additional process resource is started. Instead, the running process resource is reused and false is returned.

Es wird also kein neuer Prozess gestartet. Ist nur die Frage wie man das deuten soll. Wird der zweite Aufruf ignoriert oder wird der zweite Prozess nach Beenden des ersten ausgeführt.

C
christof.k Themenstarter:in
159 Beiträge seit 2005
vor 19 Jahren

Suppi, das bringt ja wirklich licht ins dunkel.

Vielleicht direkt noch eine frage, wenn ich nun doch auf die Anwendung warte, die ich gestartet habe, und dann mir den stdout anschauen möchte:

StreamReader sr = localprocess.StandardOutput;

Wie groß ist der Puffer? Erhalten ich wirklich die komplette Ausgabe? Es hätte ja sein können, dass das Programm megebytes an text rausschmeißt?

bis bald
Christof