设为首页 加入收藏

TOP

C#中 Process的扩展类ProcessExtensions(一)
2014-11-24 14:34:33 来源: 作者: 【 】 浏览:3
Tags:Process 扩展 ProcessExtensions

///


/// Process extensions
///

public static class ProcessExtensions
{
#region Functions


#region KillProcessAsync


///


/// Kills a process
///

/// Process that should be killed
/// Amount of time (in ms) until the process is killed.
public static void KillProcessAsync(this Process Process, int TimeToKill = 0)
{
if (Process == null)
throw new ArgumentNullException("Process");
ThreadPool.QueueUserWorkItem(delegate { KillProcessAsyncHelper(Process, TimeToKill); });
}


///


/// Kills a list of processes
///

/// Processes that should be killed
/// Amount of time (in ms) until the processes are killed.
public static void KillProcessAsync(this IEnumerable Processes, int TimeToKill = 0)
{
if (Processes == null)
throw new ArgumentNullException("Processes");
Processes.ForEach(x => ThreadPool.QueueUserWorkItem(delegate { KillProcessAsyncHelper(x, TimeToKill); }));
}


#endregion


#region GetInformation


///


/// Gets information about all processes and returns it in an HTML formatted string
///

/// Process to get information about
/// Should this be HTML formatted
/// An HTML formatted string
public static string GetInformation(this Process Process, bool HTMLFormat = true)
{
StringBuilder Builder = new StringBuilder();
return Builder.Append(HTMLFormat "" : "")
.Append(Process.ProcessName)
.Append(" Information")
.Append(HTMLFormat "

" : "\n")
.Append(Process.DumpProperties(HTMLFormat))
.Append(HTMLFormat "
" : "\n")
.ToString();
}


///


/// Gets information about all processes and returns it in an HTML formatted string
///

/// Processes to get information about
/// Should this be HTML formatted
/// An HTML formatted string
public static string GetInformation(this IEnumerable Processes, bool HTMLFormat = true)
{
StringBuilder Builder = new StringBuilder();
Processes.ForEach(x => Builder.Append(x.GetInformation(HTMLFormat)));
return Builder.ToString();
}


///


/// Get information of the process name
///

/// Process to get information about
///
public static string GetInformation(this Process Process)
{
return Process.ProcessName;
}


///


/// Gets information about all processes and returns it in string
///

/// Processes to get information about
/// string
public static string GetInformation(this IEnumerable Processes)
{
StringBuilder Builder = new StringBuilder();
Processes.ForEach(x => Builder.Append(x.GetInformation()));
return Builder.ToString();
}


#endregion


#endregion


#region Private Static Functions


///


/// Kills a process asyncronously
///

/// Name of the process to kill
/// Amount of time until the process is killed
private static void KillProcessAsyncHelper(Process Proc
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C#中为多线程变量提供原子操作的.. 下一篇C# 邮件发送方法【webMail方式】

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: