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 6779471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:23:20+00:00 2026-05-26T16:23:20+00:00

I created a multithreading C# COM-Assembly, I used it from VB6. The C#-COM can

  • 0

I created a multithreading C# COM-Assembly, I used it from VB6.

The C#-COM can fire events from multiple threads, I created an invisible From-object and use this to synchronize all events before raise them.

if (myForm.InvokeRequired() )
{
  delOnMessage myDelegate = new delOnMessage(Message_received);
  myForm.Invoke(myDelegate, new object[] { null, null });
}
else
{
  RaiseMyEvent();
}

But if the VB6-Code is inside of an event handler and calls some methods of the COM-Object, this can produce a new event.

Private Sub m_SomeClass_SomeEvent(obj As Variant)
    COMobject.SendAnAnswer() ' This produces a new event
End Sub

In that case a part of the event-system stops working, suprisingly the Main VB6 Applikation still works.

EDIT: More detailed
If the C#-COM received a Message (from CAN-Bus-Thread) it creates an event, in some cases the VB6 calls a C#-COM method which creates an event, this event is reached the VB6 too.
But then the CAN-Bus-Thread seems to be blocked, as no more messages are received (till program restart).
But other events can occur.

The CAN-Bus-Thread is an endless loop to receive a message and fire an event.

I have two questions:

Is my way of synchronizing correct?
Is it possible without modifying the VB6-code to get it working?

  • 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-05-26T16:23:21+00:00Added an answer on May 26, 2026 at 4:23 pm

    I created an invisible From-object

    That sounds like trouble. Using InvokeRequired is a dangerous anti-pattern. It is especially lethal with VB6, its runtime has badly broken thread handling. You know that the code is being called from a worker thread, use InvokeRequired only to verify that the form you use to synchronize is in the proper state to do so correctly:

    if (!myForm.InvokeRequired()) {
        throw new InvalidOperationException("Synchronization window not created");
    }
    delOnMessage myDelegate = new delOnMessage(FireMessageReceivedEvent);
    myForm.BeginInvoke(myDelegate, new object[] { null, null });
    

    Odds are good that this exception will throw, creating an invisible form is not that easy. You can force the form’s Handle property to be created by reading its Handle property. Or by overriding its SetVisibleCore() method to keep the form invisible:

        protected override void SetVisibleCore(bool value) {
            if (!this.IsHandleCreated) {
                this.CreateHandle();
                value = false;
            }
            base.SetVisibleCore(value);
        }
    

    It is however very important that you call this form’s Show() method on the main thread. It still won’t work correctly if you create the form in your worker thread. There’s no easy way to check for this in your code. Use the debugger and the Debug + Windows + Threads window to verify this.

    Last but not least, do favor BeginInvoke() instead of Invoke(). This has much smaller odds of creating deadlock. This can cause problems by itself however, your worker thread may need to be throttled to prevent it flooding the main thread with invoke requests.

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

Sidebar

Related Questions

Created .NET WCF service, tested it - works. Generated schemas from Data and service
I am learning about threading and multithreading..so i just created a small application in
I'm puzzling over how multithreading can work with delegates. The main thread has an
I created two (or more) threads to insert data in a table in database.
I used this tutorial http://delphi.about.com/od/kbthread/a/thread-gui.htm to create a class that asynchronously downloads a file
I have a server in Java which is multithreading, and I've created a thread
I use MVVM pattern in my multithreading WPF app. Now in the model I
Is it possible to create a multithreading application in VC6 with boost library? If
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I

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.