thread pool

发表于:2007-06-30来源:作者:点击数: 标签:
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 c
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#TodayCustomWizardsThreadPoolTemplate.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#TodayCustomWizards. 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 FilesMicrosoft Visual Studio.NETVC#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 FilesMicrosoft Visual Studio.NET.
3.    Compile the CustomWizard project.
4.    Copy CustomWizard.dll to C:Program FilesMicrosoft Visual Studio.NETCommon7IDE. This is again assuming the default install path for Visual Studio .NET.
5.    Run the following command on the file copied in the previous step. This registers the managed component as a COM component.
regasm CustomWizard.dll
The following screen shot shows our custom project template in the New Project dialog box.
Conclusion
Custom project templates and wizards are a great way for developers to write boilerplate code once, and have it automatically generated for subsequent use. Visual Studio .NET makes it fairly easy to write these custom wizards, and the code for hooking up a custom template is little more than a few lines of code, as shown in this article@#s sample. Any canned code that is copied over and over again for new projects should be a prime candidate for a custom project template.
Happy .NETing.
 

原文转自:http://www.ltesting.net