powered by simpleCommunicator - 2.0.27     © 2024 Programmizd 02
Map
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Не выхожу из процесса
3 сообщений из 3, страница 1 из 1
Не выхожу из процесса
    #40083208
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
private string RunProcess(string proc_name, string proc_args, Test test)
        {
            /* Create a new process object*/
            Process proc = new Process();
            /* StartInfo contains the startup information of the new process */
            proc.StartInfo.FileName = proc_name;
            proc.StartInfo.Arguments = proc_args;
            /* These two optional flags ensure that no DOS window appears */
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            /* This ensures that you get the output from the DOS application */
            proc.StartInfo.RedirectStandardOutput = true;
            try
            {
                // Start the process
                proc.Start();
                if (test.exemode != BaseTest.ExeMode.Static)
                {
                    // Wait that the process exits
                    proc.WaitForExit(process_wait_delay);
                    // Now read the output of the DOS application 
                    return proc.StandardOutput.ReadToEnd().ToString();
                }
                else
                    return "";
            }
            catch (Exception ex)
            {
                return "Process Error: " + ex.Message; //ex.ToString();
            }
        }



Если процесс отвечает то всё прекрасно. Если процесс не отвечает или виснет - proc.WaitForExit(process_wait_delay); не работает и прога виснет навечно. Почему?
...
Рейтинг: 0 / 0
Не выхожу из процесса
    #40083219
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Пробую так
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
private string RunProcess(string proc_name, string proc_args, Test test)
        {
            /* Create a new process object*/
            Process proc = new Process();
            /* StartInfo contains the startup information of the new process */
            proc.StartInfo.FileName = proc_name;
            proc.StartInfo.Arguments = proc_args;
            /* These two optional flags ensure that no DOS window appears */
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            /* This ensures that you get the output from the DOS application */
            proc.StartInfo.RedirectStandardOutput = true;
            try
            {
                // Start the process
                proc.Start();
              
                    // Wait that the process exits
                    bool result = proc.WaitForExit(process_wait_delay);
                     
                     if (result)
                        // Now read the output of the DOS application 
                        return proc.StandardOutput.ReadToEnd().ToString();
                     else
                     {
                          proc.Kill();
                          proc.Close();
                          return "";
                     }
            }
            catch (Exception ex)
            {
                return "Process Error: " + ex.Message; //ex.ToString();
            }
        }



Но теперь proc.StandardOutput.ReadToEnd().ToString(); замораживает мне весь GUI несмотря на то что RunProcess бежит в отдельном процессе. Не понимаю как разрулить это.
...
Рейтинг: 0 / 0
Не выхожу из процесса
    #40083222
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Весь call stack такой

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
private string RunProcess(string proc_name, string proc_args, Test test)
{
    /* Create a new process object*/
    Process proc = new Process();
    /* StartInfo contains the startup information of the new process */
    proc.StartInfo.FileName = proc_name;
    proc.StartInfo.Arguments = proc_args;
    /* These two optional flags ensure that no DOS window appears */
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.CreateNoWindow = true;
    /* This ensures that you get the output from the DOS application */
    proc.StartInfo.RedirectStandardOutput = true;
    try
    {
        // Start the process
        proc.Start();
        // Wait that the process exits
        bool result = proc.WaitForExit(process_wait_delay);

        if (result == true)
        {
            // Now read the output of the DOS application 
            return proc.StandardOutput.ReadToEnd().ToString();
                    
        }
        else
        {
            proc.Kill();
            proc.Close();
            return "";
        } 
    }          
    catch (Exception ex)
    {
       return "Process Error: " + ex.Message; 
    }

    return "";
}

private BaseTest.Result StepRun(Test test, ref string result)
{
    result_str = RunProcess(exe_name, arguments, test);
}


private void SequenceRun()
{
    foreach (ListViewItem item in listViewSteps.Items)
    {
        //some code here
         StepRun(current_test, ref step_data);
        //some code here  
    }
}


private void runStepsToolStripMenuItem_Click(object sender, EventArgs e)
{
    Thread steps_run = new Thread(SequenceRun);
    steps_run.Start();
}




Несмотря на то что steps_run отдельный Thread - RunProcess->return proc.StandardOutput.ReadToEnd().ToString(); замораживает GUI.
Как можно исправить это?
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Не выхожу из процесса
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали тему (0):
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]