当前位置: 首页>>代码示例>>C#>>正文


C# Process.?.Dispose方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.?.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Process.?.Dispose方法的具体用法?C# Process.?.Dispose怎么用?C# Process.?.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.?.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckCompiler

 private bool CheckCompiler()
 {
     CheckCompilerBinary();
     idleTimer?.Destroy();
     if (BinaryPath == null) return false;
     if (process != null && !process.HasExited) return true;
     PurgeOldLogs();
     Shutdown();
     var args = new [] {"/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory)};
     try
     {
         process = new Process
         {
             StartInfo =
             {
                 FileName = BinaryPath,
                 Arguments = string.Join(" ", args),
                 CreateNoWindow = true,
                 UseShellExecute = false,
                 RedirectStandardInput = true,
                 RedirectStandardOutput = true
             },
             EnableRaisingEvents = true
         };
         string path;
         switch (Environment.OSVersion.Platform)
         {
             case PlatformID.Win32S:
             case PlatformID.Win32Windows:
             case PlatformID.Win32NT:
                 var currentPath = process.StartInfo.EnvironmentVariables["PATH"] ?? Environment.GetEnvironmentVariable("PATH");
                 path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")}";
                 var newPath = string.IsNullOrEmpty(currentPath) ? path : $"{currentPath}{Path.PathSeparator}{path}";
                 process.StartInfo.EnvironmentVariables["PATH"] = newPath;
                 break;
             case PlatformID.Unix:
             case PlatformID.MacOSX:
                 var currentLdLibraryPath = process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] ?? Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                 path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")}";
                 var newLdLibraryPath = string.IsNullOrEmpty(currentLdLibraryPath) ? path : $"{currentLdLibraryPath}{Path.PathSeparator}{path}";
                 process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = newLdLibraryPath;
                 break;
         }
         process.Exited += OnProcessExited;
         process.Start();
     }
     catch (Exception ex)
     {
         process?.Dispose();
         process = null;
         Interface.Oxide.LogException("Exception while starting compiler: ", ex);
         if (ex.GetBaseException() != ex) Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
     }
     if (process == null) return false;
     client = new ObjectStreamClient<CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
     client.Message += OnMessage;
     client.Error += OnError;
     client.Start();
     return true;
 }
开发者ID:AEtherSurfer,项目名称:Oxide,代码行数:60,代码来源:PluginCompiler.cs

示例2: CheckCompiler

 private bool CheckCompiler()
 {
     CheckCompilerBinary();
     idleTimer?.Destroy();
     if (BinaryPath == null) return false;
     if (process != null && !process.HasExited) return true;
     PurgeOldLogs();
     Shutdown();
     var args = new [] {"/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory)};
     try
     {
         process = new Process
         {
             StartInfo =
             {
                 FileName = BinaryPath,
                 Arguments = string.Join(" ", args),
                 CreateNoWindow = true,
                 UseShellExecute = false,
                 RedirectStandardInput = true,
                 RedirectStandardOutput = true
             },
             EnableRaisingEvents = true
         };
         process.Exited += OnProcessExited;
         process.Start();
     }
     catch (Exception ex)
     {
         process?.Dispose();
         process = null;
         Interface.Oxide.LogException("Exception while starting compiler: ", ex);
         if (ex.GetBaseException() != ex) Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
     }
     if (process == null) return false;
     client = new ObjectStreamClient<CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
     client.Message += OnMessage;
     client.Error += OnError;
     client.Start();
     return true;
 }
开发者ID:906507516,项目名称:Oxide,代码行数:41,代码来源:PluginCompiler.cs


注:本文中的System.Diagnostics.Process.?.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。