Now that we have seen the thread pool classes, let us move to creating the object that will handle our custom project template. This is a simple C# class library project, with a single class that implements the IDTWizard interface.
public class CustomWizard : IDTWizard
{
public void Execute(object application, int hwndOwner,
ref object[] contextParams, ref object[] customParams,
ref EnvDTE.wizardResult retval)
{
string lProjName = (string)contextParams[1];
string lSolnName = (string)contextParams[2];
if (!Directory.Exists (lSolnName))
Directory.CreateDirectory (lSolnName);
_DTE lApp = (_DTE)application;
_Solution lSoln = lApp.Solution;
lSoln.Create (lSolnName, lProjName);
lSoln.AddFromTemplate(mProjPath,lSolnName,lProjName,false);
}
// NOTE: change this to the path where you store the downloaded files
private const string mProjPath =
@"C:\C#Today\CustomWizards\ThreadPoolTemplate.csproj";
}
The code block above is all we need for our custom wizard component. The first thing we do in this method is to retrieve the names of the project and the solution that is input by the user in the New Project dialog box. Once that is done, we check to see if the user input path exists, and if not, we use the System.IO.Directory class to create the specified folders. We then use the Solution object from the Visual Studio .NET object model to create a new solution and project based on our ThreadPool classes. We use the AddFromTemplate method of the Solution class to copy over the project files from the thread pool project.
Readers should change the mProjPath variable to point to the location where they have stored the ThreadPoolTemplate.csproj and ThreadPool.cs files.
The .vsdir file for this project template is shown below. We used the Guidgen tool to generate a unique GUID.
Thread Pooled Application.vsz|0|0|0|Generates a
thread pool class.|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4553|0|0
The .vsz file is as shown below.
VSWIZARD 7.0
Wizard=CustomWizardNS.CustomWizard
Attached Sample Code
The attached sample code contains the CustomWizard and ThreadPoolTemplate projects, and the support vsdir and vsz files.
Please carry out the following steps to set up this sample:
1. Copy the ThreadPool.cs and ThreadPoolTemplate.csproj files to C:\C#Today\CustomWizards. If you need to copy these to a different path, you will have to change the mProjPath member variable in the CustomWizard class from the CustomWizard project.
2. Copy the Thread Pooled Application.vsdir and Thread Pooled Application.vsz files to C:\Program Files\Microsoft Visual Studio.NET\VC#\CSharpProjects. Note that this path will be different if you have installed Visual Studio .NET in a different location. Substitute your install path for C:\Program Files\Microsoft Visual Studio.NET.
3. Compile the CustomWizard project.
4. Copy Custom