Process.Start를 호출하지만 현재 스레드를 차단합니다.Process.Start가 차단 중입니다.
pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe");
// Start process
mProcess = new Process();
mProcess.StartInfo = pInfo;
if (mProcess.Start() == false) {
Trace.TraceError("Unable to run process {0}.");
}
프로세스가 닫히더라도 코드는 더 이상 응답하지 않습니다.
하지만 Process.Start가 실제로 차단되어 있어야합니까? 무슨 일이야?
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
namespace Test
{
class Test
{
[STAThread]
public static void Main()
{
Thread ServerThread = new Thread(AccepterThread);
ServerThread.Start();
Console.WriteLine (" --- Press ENTER to stop service ---");
while (Console.Read() < 0) { Application.DoEvents(); }
Console.WriteLine("Done.");
}
public static void AccepterThread(object data)
{
bool accepted = false;
while (true) {
if (accepted == false) {
Thread hThread = new Thread(HandlerThread);
accepted = true;
hThread.Start();
} else
Thread.Sleep(100);
}
}
public static void HandlerThread(object data)
{
ProcessStartInfo pInfo = new ProcessStartInfo("C:\\Windows\\notepad.exe");
Console.WriteLine("Starting process.");
// Start process
Process mProcess = new Process();
mProcess.StartInfo = pInfo;
if (mProcess.Start() == false) {
Console.WriteLine("Unable to run process.");
}
Console.WriteLine("Still living...");
}
}
}
콘솔 출력은 (이 과정은 제대로 시작) :
--- 보도 과정을 시작 서비스 --- 을 중지갑니다.
찾았 :
는 [STAThread]
는 Process.Start를 차단을 만든다. STAThread and Multithreading을 읽었지만 개념을 Process.Start 동작과 연결할 수 없습니다.
AFAIK, STAThread는 이 필요합니다. by Windows.Form. Windows.Form을 사용할 때이 문제를 해결하는 방법은 무엇입니까? 뉴스 지옥에 대한
:
내 응용 프로그램을 다시 경우, 내가 제대로 응용 프로그램 작업을 실행하지만, 처음 시간 나는 디버깅을 중지하고, 다시 문제 araise을 IY를 다시 시작합니다.
응용 프로그램이 디버거없이 실행될 때 문제가 발생하지 않습니다.
'UseShellExecute' 및'ErrorDialog'를 true로 설정하고 생성되는 오류가 있는지 확인하십시오. – AMissico
"cDaemon"클래스가하는 일을 우리가 모른다는 사실을 알기는 어렵습니다. 문제를 보여주는 짧지 만 완전한 * 프로그램을 제안하십시오. –
(Console.Read와 결합 된 Application.DoEvents의 사용은 꽤 의심스러워 보입니다.) –