probleme mit StartInfo.WaitForExit()

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • probleme mit StartInfo.WaitForExit()

    hallo zusammen,

    ich habe immer noch ein kleines problem mit meiner windows anwendung.

    ich starte die kommandozeile und führe einen befehl aus.
    das ergebnis schreibe ich in ein textfeld und in eine arrylist. soweit funktioniert das auch ganz gut.
    wenn ich jetzt aber mit

    Quellcode

    1. foreach()
    auf die einzelnen elemente in der arrylist zugreifen will sieht das eher schlecht aus!
    die events kommen leider nicht schnell genung, heißt meine arrylist ist noch leer.
    ich habe das ganze mit

    Quellcode

    1. .WaitForExit()
    versucht. leider stürzt mir dann die ganze anwendung ab ohne in meinen catchblock zu laufen.

    kann mir vieleicht jemand weiter helfen?

    hier mein bisheriger code:

    Quellcode

    1. string sPathSvn = @"D:\tools\svn-win32-1.4.5\bin\svn.exe";
    2. string sUrl = "https://subversion/svn/...";
    3. string sList = "list";
    4. try
    5. {
    6. Process pro = new Process();
    7. pro.OutputDataReceived += new DataReceivedEventHandler(pro_OutputDataReceived);
    8. ProcessStartInfo psi = new ProcessStartInfo(@"C:\WINNT\system32\cmd.exe");
    9. psi.UseShellExecute = false;
    10. psi.RedirectStandardOutput = true;
    11. psi.RedirectStandardError = true;
    12. psi.RedirectStandardInput = true;
    13. psi.CreateNoWindow = true;
    14. psi.Arguments = "/c \"" + sPathSvn + " " + sList + " " + sUrl + " \"";
    15. pro.StartInfo = psi;
    16. pro.Start();
    17. pro.BeginOutputReadLine();
    18. //pro.Close();
    19. //pro.WaitForExit();
    20. foreach (string s in receivedData)
    21. {
    22. if (s == "sut/")
    23. {
    24. MessageBox.Show("test");
    25. }
    26. }
    27. receivedData.Clear();
    28. }
    29. catch (Exception o)
    30. {
    31. MessageBox.Show(o.Message + o.Source + o.InnerException);
    32. }
    33. }
    34. void pro_OutputDataReceived(object sender, DataReceivedEventArgs e)
    35. {
    36. try
    37. {
    38. if (e.Data != null && e.Data != "")
    39. {
    40. txtLabel.Invoke(new EventHandler(delegate{txtLabel.AppendText(e.Data + "\r\n");}));
    41. receivedData.Add(e.Data);
    42. }
    43. }
    44. catch (Exception o)
    45. {
    46. MessageBox.Show(o.Message + o.Source + o.InnerException);
    47. }
    48. }
    Alles anzeigen



    thx, truespin