We have received many support requests in regards to the following scenario: The host application is "hard killed" and the vsta.exe process continues to run. A "hard kill" can occur if the debugger is stopped, or the host application is terminated through the Task Manager. In hard kill scenarios, the host never has the opportunity to shut down VSTA.
The answer to this problem is an In-Host Provider (IPH). VSTA makes In-Host Providers incredibly easy to use and the SDK (v1 and v2) provide excellent documentation and a walkthrough. We now offer an IPH sample which addresses the above scenario.
The IPH Sample- Kill VSTA With Host provides IPHs, registration files, and templates for VSTA v 1 and v 2. The IPHs and registration files are set up for ShapeAppCSharp (VSTA v 1 and v2) and are easily adaptable for any host with either VSTA v 1 or v 2. The templates may be used with ShapeAppAdvancedCSharp (VSTA v 1) and ShapeAppMacroRecording (VSTA v 2). The sample also includes a walkthrough with instructions on how to incorporate the IPH with any host.
Click here to go to the IPH Sample- Kill VSTA With Host download page.
Here is an excerpt from the walkthrough:
A quick look at IPHs:
For information on IPHs please refer to the VSTA SDK, they provide detailed information and a comprehensive walkthrough which shows how to make and use an IPH. Here is a summary explanation of IPHs.
· IPHs are projects written in Visual Studio that implement the IInProcessHostInterface. For VSTA v 1, this interface is defined in Microsoft.VisualStudio.Tools.Applications.DesignTime and includes the method SetAdapter which takes in a HostAdapter. For VSTA v 2, this interface is defined in Microsoft.VisualStudio.Tools.Applications.DesignTime.v9.0 and includes the method SetAdapter which takes in an IVstaHostAdapter.
· IPHs do not have a language requirement.
· IPHs are associated with a project template. This association can be set by using ProjectGen, or editing the csproj or vbproj file (in a text editor like Notepad) of an existing template. All projects created based on the project template will use the IPH.
· Only one IPH can be associated with a template; however, one IPH may be used by multiple templates and hosts.
· IPHs must be registered with the host and in the GAC.
· The IPH runs in the same process as the VSTA DTE and has the same lifetime as the project that the IPH is associated with. Closing the project or the VSTA DTE kills the IPH, opening a different project in the VSTA DTE (only one project can be at a time in the VSTA DTE) kills the IPH.
· An IPH can be set to run with Visual Studio as well as VSTA; however, that is not addressed in this sample.
To use an IPH the following steps must be completed (for more information, see the SDK)
1) Create an IPH project- a project with a class which implements the IInProcessHost interface.
2) Add IPH’s project’s dll to the GAC (IPH must to be strongly signed).
3) Add the IPH to the host’s registry hive. A GUID is required for this step and can be produced using the GuidGen tool. Add the entries for the IPH to the config hive, then delete the context hive and run setup to re-create it.
4) Add the IPH to a project template.
5) Run setup to extract the template.
What this sample does:
This IPH checks the Running Object Table (ROT) and the local
processes for an instance of the host and kills the VSTA.exe process if one is
not found. The ROT is checked for any
VSTA remote process (“…vstaremoteprocess…”).
This process is created when the host creates a VSTA v 1 DTE (for an
example see the EnsureIDE method of ShapeApp samples) during debugging or when run
as a stand alone exe. The local
processes are checked for an instance of the host, like “ShapeAppCSharp.exe” or
“ShapeAppCSharp.vshost.exe”, which would be created by running the application
as a standalone exe or debugging it with Visual Studio. This IPH can be used both during development
and for distribution. If an instance of
the host or VSTA remote process is not found (i.e. any instance of either) then
the IPH prompts the user to save and closes the VSTA DTE.
Posted
Jan 10 2008, 09:53 PM
by
Melody