Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 42349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:19:27+00:00 2026-05-10T15:19:27+00:00

I have a Windows Workflow application that uses classes I’ve written for COM automation.

  • 0

I have a Windows Workflow application that uses classes I’ve written for COM automation. I’m opening Word and Excel from my classes using COM.

I’m currently implementing IDisposable in my COM helper and using Marshal.ReleaseComObject(). However, if my Workflow fails, the Dispose() method isn’t being called and the Word or Excel handles stay open and my application hangs.

The solution to this problem is pretty straightforward, but rather than just solve it, I’d like to learn something and gain insight into the right way to work with COM. I’m looking for the ‘best’ or most efficient and safest way to handle the lifecycle of the classes that own the COM handles. Patterns, best practices, or sample code would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:19:27+00:00Added an answer on May 10, 2026 at 3:19 pm

    I can not see what failure you have that does not calls the Dispose() method. I made a test with a sequential workflow that contains only a code activity which just throws an exception and the Dispose() method of my workflow is called twice (this is because of the standard WorkflowTerminated event handler). Check the following code:

    Program.cs

        class Program     {         static void Main(string[] args)         {             using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())             {                 AutoResetEvent waitHandle = new AutoResetEvent(false);                 workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)                  {                     waitHandle.Set();                 };                 workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)                 {                     Console.WriteLine(e.Exception.Message);                     waitHandle.Set();                 };                  WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1));                 instance.Start();                  waitHandle.WaitOne();             }             Console.ReadKey();         }     } 

    Workflow1.cs

        public sealed partial class Workflow1: SequentialWorkflowActivity     {         public Workflow1()         {             InitializeComponent();             this.codeActivity1.ExecuteCode += new System.EventHandler(this.codeActivity1_ExecuteCode);         }          [DebuggerStepThrough()]         private void codeActivity1_ExecuteCode(object sender, EventArgs e)         {             Console.WriteLine('Throw ApplicationException.');             throw new ApplicationException();         }          protected override void Dispose(bool disposing)         {             if (disposing)             {                 // Here you must free your resources                  // by calling your COM helper Dispose() method                 Console.WriteLine('Object disposed.');             }         }     } 

    Am I missing something? Concerning the lifecycle-related methods of an Activity (and consequently of a Workflow) object, please check this post: Activity ‘Lifetime’ Methods. If you just want a generic article about disposing, check this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 94k
  • Answers 94k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should just install .NET 3.5 SP1, and you'll get… May 11, 2026 at 6:46 pm
  • Editorial Team
    Editorial Team added an answer It looks like you want Asynchronous support for ASP.NET MVC.… May 11, 2026 at 6:46 pm
  • Editorial Team
    Editorial Team added an answer You could do this: SELECT TOP 1 UserID FROM UserTable… May 11, 2026 at 6:46 pm

Related Questions

I have a Windows Workflow application that uses classes I've written for COM automation.
Question: Should I write my application to directly access a database Image Repository or
I need to write a very simple WinForms application, but I often get stuck
In brief: Is it ever excusable to have assembly names and class names stored
I'm working through the book Pro WF Windows Workflow in .NET 3.5 and on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.