CHAPTER 17 PROCESSES, APPDOMAINS, AND OBJECT CONTEXTS
}
public string WorkingDirectory { get; set; }
To illustrate how to fine-tune your process startup, here is a modified version of
StartAndKillProcess(), which will load Microsoft Internet Explorer, navigate to www.facebook.com, and
show the window in a maximized state:
static void StartAndKillProcess()
{
Process ieProc = null;
// Launch Internet Explorer, and go to facebook,
// with maximized window.
try
{
ProcessStartInfo startInfo = new
ProcessStartInfo("IExplore.exe", "www.facebook.com");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
ieProc = Process.Start(startInfo);
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
}
...
}
Great! Now that you understand the role of Windows processes and how to interact with them from
C# code, you are ready to investigate the concept of a .NET application domain.
Source Code The ProcessManipulator project is included under the Chapter 17 subdirectory.
Understanding .NET Application Domains
Under the .NET platform, executables are not hosted directly within a Windows process, as is the case in
traditional unmanaged applications. Rather, a .NET executable is hosted by a logical partition within a
process termed an application domain. As you will see, a single process may contain multiple
application domains, each of which is hosting a .NET executable. This additional subdivision of a
traditional Windows process offers several benefits, some of which are as follows:
•
AppDomains are a key aspect of the OS-neutral nature of the .NET platform, given
that this logical division abstracts away the differences in how an underlying OS
represents a loaded executable.
•
AppDomains are far less expensive in terms of processing power and memory
than a full-blown process. Thus, the CLR is able to load and unload application
domains much quicker than a formal process, and can drastically improve
scalability of server applications.
635