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

  • SEARCH
  • Home
  • 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 8731331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:12:43+00:00 2026-06-13T09:12:43+00:00

This C# code is in a .NET 4.5 ComVisible assembly: C# Code [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid(22341223-9264-12AB-C1B4-B4F112014C31)]

  • 0

This C# code is in a .NET 4.5 ComVisible assembly:

C# Code

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("22341223-9264-12AB-C1B4-B4F112014C31")]
public interface IComWithTask
{
    void LongExecutionMethod(double x);
    void LongExecutionMethodAsync(double x);
}

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("23844123-9274-12CB-C1F4-B4F1521E4F33")]
public interface IComWithTaskEvents
{
    void OnLongExecutionMethodComplete(double x);
}

[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IComWithTaskEvents))]
[Guid("E4F27AA4-1932-2196-1234-121CF2722C42")]
[ProgId("ComWithTask")]
public class ComWithTask : IComWithTask
{
    [ComVisible(false)]
    public delegate void LongExecutionMethodComplete(double x);
    public event LongExecutionMethodComplete OnLongExecutionMethodComplete;

    public void LongExecutionMethod(double x)
    {
        if (OnLongExecutionMethodComplete != null)
        {
            OnLongExecutionMethodComplete(x * x);
        }
    }

    public void LongExecutionMethodAsync(double x)
    {
        Task.Factory.StartNew(state =>
        {
            var onLongExecutionMethodComplete = OnLongExecutionMethodComplete;
            if (onLongExecutionMethodComplete != null)
            {
                onLongExecutionMethodComplete(x * x);
            }
        }, null);
    }
}

From Excel 2010 32bit VBA, I’ve got the following behavior:

VBA Code

Private WithEvents oComWithTask As ComWithTask

Public Sub Class_Initialize()
    Set oComWithTask = New ComWithTask
End Sub

Public Sub LongExecutionMethod()
    ' Works as expected
    Call oComWithTask.LongExecutionMethod(2)
End Sub

Public Sub LongExecutionMethodAsync()
    ' Does NOT work!
    Call oComWithTask.LongExecutionMethodAsync(3)
End Sub

Private Sub oComWithTask_OnLongExecutionMethodComplete(ByVal x As Double)
    MsgBox x
End Sub

I am aware that I am spinning a thread inside .NET when calling LongExecutionMethodAsync, and I am aware that office applications are single threaded.

I did find a great literature on calling COM components from .NET in a multithreaded way, but couldn’t find any resource that goes the other way around, i.e. VBA calling a multithreaded .NET wrapped with COM method.

Any thoughts on how to make LongExecutionMethodAsync work with
multithreading and could you point me to any related resource on this
subject?
Also, do you have other suggestions for triggering async events in VBA?

  • 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. Editorial Team
    Editorial Team
    2026-06-13T09:12:44+00:00Added an answer on June 13, 2026 at 9:12 am

    The code above is working as expected, the problem was the life span of the object in VBA which was dying before the raise of the event.

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

Sidebar

Related Questions

This C# code is in a .NET 4.5 ComVisible assembly: C# Code [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid("22341123-9264-12AB-C1A4-B4F112014C31")]
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I have this code : http://jsfiddle.net/VAkLn/6/ When i add a table : http://jsfiddle.net/VAkLn/7/ this
Could anyone please help me convert this code to vb.net, I have tried it
In this VB.NET code: Dim o as SomeClass Try o = new SomeClass 'call
I have this vb.net code ( but I think meaning code is equivalent for
I have this code in my ASP.NET application written in C# that is trying
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression

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.