Skip to content

COM event with recursion .net 6 problem #73754

@maciejpieprzyk

Description

@maciejpieprzyk

Description

We are using a system that exposes UI interface using COM objects. It is an external application so I cannot send a minimal reproduction source code of a problem. I will try to explain the whole workflow.

Background information

There is an application interface (COM) that exposes event.

Event declaration in the App interface:

event _IApplicationEvents_StatusBarEventEventHandler StatusBarEvent;

Delegate definition:

public delegate void _IApplicationEvents_StatusBarEventEventHandler([In][MarshalAs(UnmanagedType.BStr)] string Text, [In] BoStatusBarMessageType messageType);

There is also a StatusBarControl that allows us to set up the ProgressBarMessage:

application.StatusBar.SetText(some text);

When we set the text to the status bar Event is fired.

Reproduction Steps

UseCase: When the StatusBarEvent fires with text equal to “crush” we want to change this to "****" on the status bar

EventHandler implementation:

public override void OnStatusBarDisplayed(string text, BoStatusBarMessageType messageType)
{
    if (text.Equals("crush",StringComparison.CurrentCultureIgnoreCase))
    {
        application.StatusBar.SetText("*****");
    }
}

I will provide some screenshots of the debugging session:

  1. Set "crush" to the status bar. image
  2. We get the Event notification and call the setText("****").
  3. System freezes. We can see that the event handler thread freezes on the set text method. image
  4. We can see that in the separate thread invoking a method the foreach loop of _delegateWrapper. image

Expected behavior

What should happen: this thread @29816 should invoke this method and Call the OnStatusBarDisplayed event again. This is working correctly when running in the .net framework.

Below is the same call stack of the .net framework debugging session. image

Calling SetText in another thread is not an option for us.

Actual behavior

System freezes. We can see that the event handler thread freezes on the set text method. image

Regression?

This is working correctly when running in the .net framework.

Known Workarounds

Calling SetText in another thread but this is not an option for us.

Configuration

.NET 6.0
Windows 11
x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions