在我的应用程序中,我在以这种方式Wireshark process
添加到我之前通过打开检查我的文件:Listbox
protected string[] invokeProcess(WiresharkProcesses process, string args)
{
string processToInvoke = null;
validateProcess(process);
switch (process)
{
case WiresharkProcesses.Capinfo:
processToInvoke = Path.Combine(getbBasePath, "capinfos.exe");
break;
case WiresharkProcesses.Editcap:
processToInvoke = Path.Combine(getbBasePath, "editcap.exe");
break;
case WiresharkProcesses.Tshark:
processToInvoke = Path.Combine(getbBasePath, "tshark.exe");
break;
case WiresharkProcesses.Wireshark:
processToInvoke = Path.Combine(getbBasePath, "wireshark.exe");
break;
}
ProcessStartInfo capinfosProcess = new ProcessStartInfo(processToInvoke);
capinfosProcess.Arguments = args;
capinfosProcess.WindowStyle = ProcessWindowStyle.Hidden;
capinfosProcess.RedirectStandardOutput = true;
capinfosProcess.RedirectStandardError = true;
capinfosProcess.CreateNoWindow = true;
capinfosProcess.UseShellExecute = false;
capinfosProcess.ErrorDialog = false;
List<string> lineList = new List<string>();
using (Process pros = Process.Start(capinfosProcess))
{
StreamReader reader = pros.StandardOutput;
while (!reader.EndOfStream)
{
lineList.Add(reader.ReadLine());
}
pros.WaitForExit();
}
return lineList.ToArray();
}
private static string getbBasePath
{
get
{
if (Directory.Exists(@"C:\Program Files (x86)\Wireshark"))
{
return @"C:\Program Files (x86)\Wireshark";
}
else
{
return @"C:\Program Files\Wireshark";
}
}
}
private void validateProcess(WiresharkProcesses process)
{
switch (process)
{
case WiresharkProcesses.Capinfo:
break;
case WiresharkProcesses.Editcap:
break;
case WiresharkProcesses.Tshark:
break;
case WiresharkProcesses.Wireshark:
break;
}
}
}
当我检查这些文件时,我这样做Thread
是为了防止我的 Ui 冻结,所以当我选择根文件夹时,很多进程同时打开,如果我在中间关闭我的应用程序,所有这些进程都保持打开状态并且这件事占用了很多内存。我怎样才能防止它发生?也许通过在单独的线程中打开这个进程并将这个线程配置为isBackground = true ?