MSDN Documentation – Windows API

System.Kernel.ProcessAndThread

The ProcessAndThread namespace provides classes, structures, and enumerations that enable developers to create, manage, and synchronize processes and threads on Windows operating systems.

Table of Contents

Overview

This namespace contains the core API surface for interacting with the Windows kernel's process and thread subsystems. It includes functionality for:

Classes

ClassDescription
ProcessRepresents a Windows process and provides methods to start, stop, and query processes.
ThreadEncapsulates a thread within a process and offers control over its execution.
ProcessStartInfoSpecifies a set of values that are used when starting a process.
ProcessThreadCollectionProvides a strongly-typed collection of Thread objects.

Structures

Enumerations

Code Examples

Creating a Process

using System;
using System.Diagnostics;
using SystemKernel.ProcessAndThread;

class Example
{
    static void Main()
    {
        var startInfo = new ProcessStartInfo
        {
            FileName = "notepad.exe",
            Arguments = "",
            UseShellExecute = false,
            RedirectStandardOutput = false
        };

        using var process = Process.Start(startInfo);
        Console.WriteLine($"Started Process Id: {process.Id}");
        process.WaitForExit();
        Console.WriteLine("Process exited.");
    }
}

Creating a Thread

using System;
using SystemKernel.ProcessAndThread;

class ThreadDemo
{
    static void Main()
    {
        var thread = new Thread(() =>
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine($"Thread working {i}");
                Thread.Sleep(500);
            }
        });

        thread.Start();
        thread.Join();
        Console.WriteLine("Thread completed.");
    }
}

Enumerating Running Processes

using System;
using SystemKernel.ProcessAndThread;

class ListProcesses
{
    static void Main()
    {
        foreach (var proc in Process.GetProcesses())
        {
            Console.WriteLine($"{proc.Id,5}  {proc.ProcessName}");
        }
    }
}