.NET ITaskHandler Implementation

Rating:        Based on 1 rating
Reviewed:  1 review
Downloads: 426
Change Set: 81594
Released: Nov 30, 2012
Updated: Nov 30, 2012 by dahall
Dev status: Stable Help Icon

Recommended Download

Source Code COMTask.zip
source code, 6K, uploaded Nov 30, 2012 - 426 downloads

Release Notes

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:
  1. Create your own C# Class Library project
  2. Add the TaskHandlerBase.cs file from this download into the project
  3. 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)]
[Transaction(TransactionOption.Required)]
[ComVisible(true), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
[ClassInterface(ClassInterfaceType.None)]
  • 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: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationName("My COM Task")]
[assembly: Description("COM Task for Sample ITaskHandler implementation.")]
[assembly: ApplicationAccessControl(true,
   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
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegSvcs.exe "$(TargetPath)"

Reviews for this release

     
Best in class support for COMHandler Action. Keep it up Mr. Dahall
by jojo_jojo on Apr 16, 2014 at 10:22 AM