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

Posted on 2012-08-17
Last Modified: 2012-08-17
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 .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,
Question by:DjJohnny
    1 Comment
    LVL 74

    Accepted Solution

    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now