If you want to use the COMHandlerAction action to run code in a startable in-process library, you have to implement the ITaskHandler interface. There are some interesting tricks to making this work. This project contains a working class library that exposes a COM object which implements ITaskHandler. It contains the Interop code for the interfaces. This is a nice option as you don't need to load an executable. A few things to note:
- Create your own C# Class Library project
- Add the TaskHandlerBase.cs file from this download into the project
- Create a new class for your new handler
- Inherit TaskHandlerBase
- Create a new GUID (Tools | Create GUID)
- Add the following attributes to the class replacing the Guid attribute with the value from the prior step
[ObjectPooling(MinPoolSize = 2, MaxPoolSize = 10, CreationTimeout = 20)]
- Override any appropriate methods from the TaskHandlerBase class. At a minimum, you must override the Start(string data) method. See the MSDN documentation for ITaskHandler to understand the purposes of the four overridable methods.
- In your Properties\AssemblyInfo.cs file, add the following code and insert your own values for ApplicationName and Description. Update the ApplicationAccessControl if desired.
[assembly: ApplicationName("My COM Task")]
[assembly: Description("COM Task for Sample ITaskHandler implementation.")]
AccessChecksLevel = AccessChecksLevelOption.ApplicationComponent,
Authentication = AuthenticationOption.Packet,
ImpersonationLevel = ImpersonationLevelOption.Identify)]
[assembly: SecurityRole("Tester", SetEveryoneAccess = true)]
- In the project's properties "Application | Assembly Information" area, select "Make assembly COM-visible"
- In the project's properties "Signing" tab, sign the assembly with a new key file.
- In the project's properties "Build Events" tab, enter the following in the "Post-build event command line:" box