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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:37:50+00:00 2026-05-19T22:37:50+00:00

I have an COM component that I am fixing at the moment that is

  • 0

I have an COM component that I am fixing at the moment that is used within a VB6 application (and Raises Events) to the hosting VB6 program.

This Component uses Multiple Threads to perform it’s work internally and then moves the events out to the layer that is actually exposed to the VB6 application.

In the constructor of the Component that is called via the VB6 Application (New MyObject) this block of code within the component gets called

public sub New()
  mSyncContext = System.Threading.SynchronizationContext.Current
  If mSyncContext Is Nothing Then
      Using f As New Windows.Forms.Form
         mSyncContext = System.Threading.SynchronizationContext.Current
      End Using
  End If
end sub 

within the threads they raiseevents that are received in this outer object.

the events eventually find their way into CommsCommunicationsError, which then does some tricks to get it onto the Correct thread for raising events into VisualBasic6.

Private Sub CommsCommunicationsError(ByVal theErrorNumber As Integer, ByVal theOrder As Order)
  mRecordingCounter += 1

  Dim args As OrderErrorEventArgs
  If theOrder.Parent IsNot Nothing Then
      args = New OrderErrorEventArgs(theErrorNumber, theOrder.Parent, mRecordingCounter)
  Else
      args = New OrderErrorEventArgs(theErrorNumber, theOrder, mRecordingCounter)
  End If

  PostToCommunicationsError(args)
End Sub

Private Sub PostToCommunicationsError(ByVal args As OrderErrorEventArgs)
  mSyncContext.Post(AddressOf CommunicationsErrorSend, args)
End Sub

Private Sub CommunicationsErrorSend(ByVal state As Object)
  Dim args As OrderErrorEventArgs = CType(state, OrderErrorEventArgs)
  onCommunicationsError(args)
End Sub

Private Sub onCommunicationsError(ByVal args As OrderErrorEventArgs)
  RaiseEvent CommunicationsError(args.ErrorNumber, args.Order)
End Sub

Is this how is should be getting done, as I am sometimes seeing random crashes in the application at the point when one of these events would be raised.

Should the Threads have their apartmentstate changed to STA(maybe) instead of MTA(the default)?

  • 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-19T22:37:50+00:00Added an answer on May 19, 2026 at 10:37 pm

    I found that for the solution to this problem there was no requirement to alter the threading model. The issues had nothing to do with multi-threading. It was the networking code that was running behind the scenes in it’s own thread that was creating exceptions and causing the main thread to fail (even though it was not supposed to)

    Removing the Context Posting code consistently caused errors (of a different nature) that looked like the same thing, but they were consistent rather than random like the network code.

    IMO I would recommend leaving threading apartments alone (use the defaults).

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

Sidebar

Related Questions

I have a 32 bit COM component that is used mostly by ASP, we
I have a COM component written in C# that makes calls to ConfigurationManager.AppSettings.Get(...). This
I have installed my windows application that uses TeeChart ActiveX (a COM Component for
We have a classic ASP application that connects to a COM component. The COM
I have a web application that uses an ActiveX COM component, for example: <OBJECT
I have a COM component written in VB6 that I'm using from a Visual
I have a COM component written in C++ that has a Print function. This
I have a C# application which uses a COM component. This COM component require
I have an STA COM component which is put into a COM+ application. The
We have a a VB6 app (in a COM component) which uses CDate() to

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.