Refactor the TorWebClient
This commit is contained in:
@@ -442,31 +442,40 @@ namespace TorWebClient
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try{Program.SetConsoleCtrlHandler(new HandlerRoutine(Program.ConsoleCtrlCheck),true);}
|
||||
catch(Exception exception){Console.WriteLine(exception.ToString());}
|
||||
if(!Utility.IsAdministrator())
|
||||
try
|
||||
{
|
||||
Console.WriteLine("TorProxy needs to be under administrator account. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
MDTrace.LogLevel=LogLevel.DEBUG;
|
||||
String strLogFile="torwebclient.log";
|
||||
Utility.DeleteFile(strLogFile);
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
|
||||
try{Program.SetConsoleCtrlHandler(new HandlerRoutine(Program.ConsoleCtrlCheck),true);}
|
||||
catch(Exception exception){Console.WriteLine(exception.ToString());}
|
||||
if(!Utility.IsAdministrator())
|
||||
{
|
||||
Console.WriteLine("TorProxy needs to be under administrator account. Press any key to exit.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
MDTrace.LogLevel=LogLevel.DEBUG;
|
||||
String strLogFile="torwebclient.log";
|
||||
Utility.CopyFile(strLogFile,Utility.DateTimeToStringYYYYMMDDMMSSTT(DateTime.Now)+strLogFile);
|
||||
Utility.DeleteFile(strLogFile);
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
|
||||
|
||||
ManualResetEvent[] resetEvents=new ManualResetEvent[1];
|
||||
for(int index=0;index<resetEvents.Length;index++) resetEvents[index]=new ManualResetEvent(false);
|
||||
resetEvents[0].Reset();
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
ManualResetEvent[] resetEvents=new ManualResetEvent[1];
|
||||
for(int index=0;index<resetEvents.Length;index++) resetEvents[index]=new ManualResetEvent(false);
|
||||
resetEvents[0].Reset();
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
Program.GetInstance().Start();
|
||||
Program.GetInstance().ResetEvent=resetEvents[0];
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Running...");
|
||||
});
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Waiting for terminal event...");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Terminated...");
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
Program.GetInstance().Start();
|
||||
Program.GetInstance().ResetEvent=resetEvents[0];
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Running...");
|
||||
});
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Waiting for terminal event...");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Terminated...");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception: {0}",exception.ToString()));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user