Game Development Reference
In-Depth Information
{
e.MainForm.WindowState = FormWindowState.Normal;
}
// Activate the main form
e.MainForm.Activate();
((MainForm)e.MainForm).HandleCommandLine(e.CommandLine);
}
The MainForm class is a simple form that has a method called HandleCommandLine .
This method takes in a ReadOnlyCollection<string> instance that contains the com-
mand line parameters. It is now up to you how to determine how these parame-
ters are handled!
Conclusion
In this chapter I began by discussing the necessity of the singleton pattern for
application instances, and then later I detailed a variety of ways to implement such
a pattern. Each method is better suited to a different situation, though the best
approach when at all possible is to use the ApplicationServices component. This
approach offers the least amount of work to implement, and is trivial to maintain.
Perhaps in the future, this functionality will be refactored into a more general
component that is “natively” supported by Visual C# .NET, but at the moment, it
seems to be the best way to handle single application instances with the least
amount of code and effort to maintain it.
Aside from the ApplicationServices component, the other approaches did not
show how to pass command line parameters to the initial instance. This can be
done using .NET Remoting, a TCP\IP loopback channel, or even the WM_COPYDATA
event and the Win32 message pump. This functionality is beyond the scope of this
chapter, but is covered in Parts IV and V of this topic.
The Companion Web site contains the full source code and examples to the solu-
tions presented in this chapter.
Search Nedrilad ::




Custom Search