本文整理汇总了C#中System.Diagnostics.Process.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Dispose方法的具体用法?C# Process.Dispose怎么用?C# Process.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFirewallRule
static bool AddFirewallRule()
{
//accomplished via shelling out to netsh.exe with relevant arguments.
Process proc = new Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.UseShellExecute = false; //the process should be created directly from this app.
proc.StartInfo.RedirectStandardError = true; //allowed since we set UseShellExecute to false
proc.StartInfo.FileName = "netsh.exe"; //would include the folder name if not in system path
proc.StartInfo.Arguments = "advfirewall firewall add rule name=\"Banned IP Addresses\" dir=in action=block description=\"IPs detected from Security Event Log with more than 10 failed attempts a day\" enable=yes profile=any localip=any protocol=any interfacetype=any";
proc.StartInfo.CreateNoWindow = true;
string errstr = "";
try
{
OutputMsg("Starting netsh.exe to add firewall rule");
proc.Start();
errstr = proc.StandardError.ReadToEnd();
proc.WaitForExit();
}
catch (Exception e)
{
OutputMsg("Unable to add firewall rule. Error starting process for netsh.exe" , e.ToString());
proc.Dispose();
return false;
}
if (errstr != "")
{
OutputMsg("Suspicious output from netsh.exe:\n\t" + errstr +
"\n*** Check to verify that the update was processed correctly. ***");
}
proc.Dispose();
return true;
}
示例2: RetrieveDataFromSubversion
private XmlDocument RetrieveDataFromSubversion(string subversionArguments)
{
var subversionClient = new Process();
subversionClient.StartInfo.CreateNoWindow = true;
subversionClient.StartInfo.UseShellExecute = false;
subversionClient.StartInfo.RedirectStandardOutput = true;
subversionClient.StartInfo.RedirectStandardInput = true;
subversionClient.StartInfo.RedirectStandardError = true;
subversionClient.StartInfo.FileName = _subversionPath;
subversionClient.StartInfo.Arguments = subversionArguments;
Console.WriteLine("Starting subversion client...");
subversionClient.Start();
Console.WriteLine("Collecting subversion client output...");
string output = subversionClient.StandardOutput.ReadToEnd();
subversionClient.WaitForExit();
subversionClient.Close();
subversionClient.Dispose();
Console.WriteLine("Subversion output collected.");
return new XmlDocument {InnerXml = output};
}
示例3: StartIisExpress
private static void StartIisExpress()
{
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
ErrorDialog = true,
LoadUserProfile = true,
CreateNoWindow = false,
UseShellExecute = false,
Arguments = string.Format("/path:\"{0}\" /port:{1}",
@"C:\Users\ian\Documents\Visual Studio 2015\Projects\SimpleCalculator\SimpleCalculator",
"8888")
};
var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
? startInfo.EnvironmentVariables["programfiles(x86)"]
: startInfo.EnvironmentVariables["programfiles"];
startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";
try
{
_iisProcess = new Process { StartInfo = startInfo };
_iisProcess.Start();
_iisProcess.WaitForExit();
}
catch
{
_iisProcess.CloseMainWindow();
_iisProcess.Dispose();
}
}
示例4: Start
public Boolean Start()
{
//FileInfo commandFile = new FileInfo(_commandFullPath);
//if(commandFile.Exists == false) throw new FileNotFoundException();
Boolean result = false;
Process p = new Process();
p.StartInfo.FileName = _command;
if(_arugment.IsNullOrEmpty() == false) p.StartInfo.Arguments = _arugment;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
// These two optional flags ensure that no DOS window appears
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
ErrorMessage = p.StandardError.ReadToEnd();
OutputMessage = p.StandardOutput.ReadToEnd();
if(p.ExitCode == 0) result = true;
p.Close();
p.Dispose();
return result;
}
示例5: FLV_encode
public string FLV_encode(string filename, string width, string height, string bitrate, string samplingrate)
{
try
{
string rootpath = Server.MapPath(Request.ApplicationPath);
string inputpath = rootpath + "\\lib\\up\\v";
string outputpath = rootpath + "\\lib\\up\\v";
string _ffmpegpath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.dll");
string outfile = "";
string size = width + "*" + height;
outfile = System.IO.Path.GetFileNameWithoutExtension(inputpath + filename);
outfile = outfile + ".flv";
string ffmpegarg = " -i " + inputpath + filename + " -acodec libmp3lame -ar " + samplingrate + " -ab " + bitrate + " -f flv -s " + size + " " + inputpath + outfile;
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = _ffmpegpath;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.StartInfo.Arguments = ffmpegarg;
pProcess.EnableRaisingEvents = true;
pProcess.Start();
pProcess.WaitForExit();
pProcess.Close();
pProcess.Dispose();
return outfile;
}
catch (Exception err)
{
return "KO";
}
}
示例6: PDF2SWF
/// <summary>
/// PDF格式转为SWF
/// </summary>
/// <param name="pdfPath">PDF文件地址</param>
/// <param name="swfPath">生成后的SWF文件地址</param>
/// <param name="beginpage">转换开始页</param>
/// <param name="endpage">转换结束页</param>
private static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
{
string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf-0.9.1.exe");
pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
swfPath = HttpContext.Current.Server.MapPath(swfPath);
if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
{
return false;
}
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -s flashversion=9");
if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
sb.Append(" -j " + photoQuality);
string Command = sb.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}
示例7: Run
public bool Run(string text, string host, out object results)
{
using (Process cmd = new Process())
{
results = null;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.FileName = "pscp.exe";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.StartInfo.Arguments = "-pw" + " " + m_userPassword + " " + text + " " + m_userName + "@" + host + ":/";
cmd.Start();
cmd.StandardInput.WriteLine("y");
cmd.StandardInput.WriteLine("exit");
if (!cmd.WaitForExit(30000))
{
cmd.Kill();
cmd.Dispose();
return false;
}
else
{
return true;
}
}
}
示例8: Execute
public static Process Execute(String command, bool waitForExit, String workingDir = null)
{
Process processToExecuteCommand = new Process();
processToExecuteCommand.StartInfo.FileName = "cmd.exe";
if (workingDir != null)
{
processToExecuteCommand.StartInfo.WorkingDirectory = workingDir;
}
processToExecuteCommand.StartInfo.Arguments = @"/C " + command;
processToExecuteCommand.StartInfo.RedirectStandardInput = true;
processToExecuteCommand.StartInfo.RedirectStandardError = true;
processToExecuteCommand.StartInfo.RedirectStandardOutput = true;
processToExecuteCommand.StartInfo.UseShellExecute = false;
processToExecuteCommand.StartInfo.CreateNoWindow = true;
processToExecuteCommand.EnableRaisingEvents = false;
processToExecuteCommand.Start();
processToExecuteCommand.OutputDataReceived += new DataReceivedEventHandler(processToExecuteCommand_OutputDataReceived);
processToExecuteCommand.ErrorDataReceived += new DataReceivedEventHandler(processToExecuteCommand_ErrorDataReceived);
processToExecuteCommand.BeginOutputReadLine();
processToExecuteCommand.BeginErrorReadLine();
if (waitForExit == true)
{
processToExecuteCommand.WaitForExit();
processToExecuteCommand.Close();
processToExecuteCommand.Dispose();
processToExecuteCommand = null;
}
return processToExecuteCommand;
}
示例9: StartIisExpress
private void StartIisExpress()
{
var applicationHostConfig = CreateApplicationHostConfig();
var applicationHostPath = Path.GetFullPath("applicationHost.config");
File.WriteAllText(applicationHostPath, applicationHostConfig);
var startInfo = new ProcessStartInfo
{
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Minimized,
CreateNoWindow = !_options.ShowIisExpressWindow,
Arguments = string.Format("/config:\"{0}\" /systray:true", applicationHostPath)
};
var programfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";
try
{
_process = new Process { StartInfo = startInfo };
_process.Start();
_manualResetEvent.Set();
_process.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Error starting IIS Express: " + ex);
_process.CloseMainWindow();
_process.Dispose();
}
}
示例10: StartIisExpress
private static void StartIisExpress()
{
var projectPath = $"{Environment.CurrentDirectory}\\..\\..\\..\\..\\ContosoUniversity.Web.Mvc\\obj\\Publish";
projectPath = System.IO.Path.GetFullPath(projectPath);
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
ErrorDialog = true,
LoadUserProfile = true,
CreateNoWindow = false,
UseShellExecute = false,
Arguments = string.Format("/path:\"{0}\" /port:{1}", projectPath, Port)
};
var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
? startInfo.EnvironmentVariables["programfiles(x86)"]
: startInfo.EnvironmentVariables["programfiles"];
startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";
try
{
_iisProcess = new Process { StartInfo = startInfo };
_iisProcess.Start();
_iisProcess.WaitForExit();
}
catch
{
_iisProcess.CloseMainWindow();
_iisProcess.Dispose();
}
}
示例11: Do
public static void Do(string cmd)
{
var process = new Process
{
EnableRaisingEvents = true,
StartInfo = new ProcessStartInfo(@"cmd.exe")
{
Arguments = "/K " + cmd,
RedirectStandardError = true,
UseShellExecute = false,
}
};
process.Exited += (sender, args) =>
{
if (process.ExitCode != 0)
{
var errorMessage = process.StandardError.ReadToEnd();
throw new InvalidOperationException(errorMessage);
}
Console.WriteLine("The process has exited.");
process.Dispose();
};
process.Start();
}
示例12: Init
public void Init()
{
//String path = v.getPath();
string ph = Environment.CommandLine;
ph = ph.Substring(0, ph.LastIndexOf('\\') + 1);
if (ph[0] == '"')
ph = ph.Substring(1);
//FileService.createBat(path, ph, options, output);
Process p = new Process();
p.StartInfo.FileName = "\"" + ph + "x264.exe\"";
p.StartInfo.Arguments = "--fullhelp";
//p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
//p.ErrorDataReceived += new DataReceivedEventHandler(Output);
p.OutputDataReceived += new DataReceivedEventHandler(Output);
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
//p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
textBox1.Text = sb.ToString();
}
示例13: ExecuteProcess
public static ProcessExecutionResult ExecuteProcess(string workingDirectory, string filepath, string arguments)
{
ProcessExecutionResult result = new ProcessExecutionResult();
Process process = new Process();
process.StartInfo.FileName = filepath;
process.StartInfo.Arguments = arguments;
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
StringBuilder testLogOut = new StringBuilder();
StringBuilder testLogErr = new StringBuilder();
ProcessListener listen = new ProcessListener(process);
listen.StdOutNewLineReady += ((obj) => testLogOut.AppendLine("stdout:" + obj)); // Log StdOut
listen.StdErrNewLineReady += ((obj) => testLogErr.AppendLine("stderror:" + obj)); // Log StdError
process.Start();
listen.Begin();
process.WaitForExit();
result.StandardError = testLogErr.ToString();
result.StandardOutput = testLogOut.ToString();
listen.Dispose();
process.Dispose();
return result;
}
示例14: StartIisExpress
private static void StartIisExpress()
{
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
ErrorDialog = true,
LoadUserProfile = true,
CreateNoWindow = false,
UseShellExecute = false,
Arguments = string.Format("/config:{0} /site:{1}", @"../../../.vs/config/applicationhost.config", "Web")
};
var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
? startInfo.EnvironmentVariables["programfiles(x86)"]
: startInfo.EnvironmentVariables["programfiles"];
startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";
try
{
_iisProcess = new Process { StartInfo = startInfo };
_iisProcess.Start();
_iisProcess.WaitForExit();
}
catch
{
_iisProcess.CloseMainWindow();
_iisProcess.Dispose();
}
}
示例15: BuildMatchingFile
/// <summary>
/// 使用Process编译,指定目录下所有匹配的文件
/// </summary>
/// <param name="parameter">The parameter.</param>
private static string BuildMatchingFile(string parameter)
{
string result;
Process process = null;
try
{
process = new Process();
process.StartInfo.FileName = "CMD";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = parameter;
process.Start();
//process.WaitForExit();
result = process.StandardOutput.ReadToEnd();
process.Close();
}
finally
{
if (process != null)
process.Dispose();
}
return result;
}