线程可执行进程的任何一部分代码,包括当前由另一线程执行的部分。

此类信息包括线程集、加载的模块(.dll 和 .exe 文件)和性能信息(如进程当前使用的内存量)。

 中的任何进程时,您必须完全限定它们。

组细分与操作系统有关。

句柄是非常有价值的资源,所以句柄泄漏比内存泄漏危害更大。

例:

下面的示例使用 Process 类的实例启动进程。

using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{    

  class MyProcess    
  {        
    public static void Main()        
    {            
      Process myProcess = new Process();            
      try
             { 
               myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true; 
               myProcess.Start();
                // This code assumes the process you are starting will terminate itself. 
                // Given that is is started without a window so you cannot terminate it
                 // on the desktop, it must terminate itself or you can do it programmatically 
               // from this application using the Kill method. 
           } 
           catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        } 
   }
}

 

下面的示例使用 Process 类本身和静态 Start 方法启动进程。

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
	/// <summary>
	/// Shell for the sample.
	/// </summary>
	class MyProcess
	{
	   
		/// <summary>
		/// Opens the Internet Explorer application.
		/// </summary>
		void OpenApplication(string myFavoritesPath)
		{
			// Start Internet Explorer. Defaults to the home page.
			Process.Start("IExplore.exe");
				    
		    // Display the contents of the favorites folder in the browser.
		    Process.Start(myFavoritesPath);

		}
		
		/// <summary>
		/// Opens urls and .html documents using Internet Explorer.
		/// </summary>
		void OpenWithArguments()
		{
			// url's are not considered documents. They can only be opened
			// by passing them as arguments.
			Process.Start("IExplore.exe", "www.northwindtraders.com");
			
			// Start a Web page using a browser associated with .html and .asp files.
			Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
			Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
		}
		
		/// <summary>
		/// Uses the ProcessStartInfo class to start new processes, both in a minimized 
		/// mode.
		/// </summary>
		void OpenWithStartInfo()
		{
			
			ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
			startInfo.WindowStyle = ProcessWindowStyle.Minimized;
			
			Process.Start(startInfo);
			
			startInfo.Arguments = "www.northwindtraders.com";
			
			Process.Start(startInfo);
			
		}

		static void Main()
		{
            		// Get the path that stores favorite links.
            		string myFavoritesPath = 
                	Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            		MyProcess myProcess = new MyProcess();

			myProcess.OpenApplication(myFavoritesPath);
			myProcess.OpenWithArguments();
			myProcess.OpenWithStartInfo();

       		}	
	}
}

相关文章:

  • 2021-12-31
  • 2021-05-29
  • 2021-08-30
  • 2022-03-02
  • 2021-06-21
  • 2022-02-18
  • 2021-12-30
  • 2022-12-23
猜你喜欢
  • 2021-11-08
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-12-31
相关资源
相似解决方案