이 대답 아니다 - 나는 ... 코멘트에이 나를 위해 작동
모든이 코드를 넣을 수 없습니다. 코드이 어떻게 다른지 말해 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace Test
{
class Program
{
const string OutputFile = @"E:\Output.txt";
object _lock = new object();
static void Main(string[] args)
{
Program program = new Program();
Thread thread = new Thread(program.ThreadMethod);
thread.Start(@"E:\Test.txt");
thread = new Thread(program.ThreadMethod);
thread.Start(@"E:\DoesntExist.txt");
Console.ReadKey();
}
void ThreadMethod(object filename)
{
String result = RunNormal(filename as string);
lock (_lock)
{
FileInfo fi = new FileInfo(OutputFile);
if (!fi.Exists)
{
try
{
fi.Create().Close();
}
catch (System.Security.SecurityException secEx)
{
Console.WriteLine("An exception has occured: {0}", secEx.Message);
return;
}
}
StreamWriter sw = fi.AppendText();
sw.WriteLine(result);
sw.Close();
}
}
string RunNormal(string fullfilename)
{
try
{
Process.Start(fullfilename);
return fullfilename + "|Success";
}
catch (Exception e)
{
return fullfilename + "|" + e.ToString();
}
}
}
}
과 Output.txt의 출력은 다음과 같습니다
E:\DoesntExist.txt|System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at Test.Program.RunNormal(String fullfilename) in E:\Projekti\VS2010\Test\Test\Program.cs:line 59
E:\Test.txt|Success
코드 얼마나 다른가요? 다른 방법을 부르니? 결과를 어떻게 처리합니까?
Console.Writeline ("성공")을 시도해 볼 수 있습니까? 그 대신 작동하는지 확인하십시오. – neeKo
나는 노력했다. 같은 결과! 이 프로세스를 시작하면 해당 스레드의 모든 내용이 중지됩니다! –
흠, 이것을 재현 할 수 없습니다 ... 프로세스를 열고 콘솔에 메시지를 보내는 스레드를 만들었으므로 제대로 작동합니다 ... 다른 작업은 무엇입니까? 프로세스 전에 중단 점을 넣으십시오. 시작 및 다음 단계를 거쳐 실제로 중지되는지 (should shouldnt) – neeKo