[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1125
  • Last Modified:

Using Me.Invoke(New EventHandler(AddressOf MySub))

Hello experts,
I am working on a application that uses a piece of hardware that is connected through a COM port. The hardware came with some sample code in VB.net .After it reads the data from the com port it calls a sub that is on the same form using
Me.Invoke(New EventHandler(AddressOf MySub))

My question is why would I call the sub this way instead of just


I have never used invoke before so I'm not quite sure how it would fit in with this. From my research I see it has something to do with multithreading. It seems to work, I would just like to understand it better why it was called this way.
Thank you,
1 Solution
käµfm³d 👽Commented:
If the application is multi-threaded, then you use Invoke to ensure the method is executed on the main thread (the UI thread) of the application. This is required by the Framework (or maybe it's better to say it's required by the CLR).

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now