///
/// 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