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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:14:27+00:00 2026-05-31T00:14:27+00:00

I am in the process of writing an application that communicates with several devices

  • 0

I am in the process of writing an application that communicates with several devices through GPIB commands, running a test on some equipment. I’ve set up a class, TestProcedure, which will start a new thread, and run the testing. Throughout testing, I’ve set up several custom events to send information back to the GUI. Here is an example of a simple event:

    public event InformationEventHandler<string> TestInfoEvent;
    /// <summary>
    /// Event raised when information should be passed back to the main testing form.
    /// </summary>
    /// <param name="s">Information to send back to form.</param>
    private void OnInfo(string s)
    {
        if (TestInfoEvent != null)
            TestInfoEvent(this, s);
    }

Which would be handled through the GUI, updating a text box like this:

TheTestProcedure.TestInfoEvent += new TestProcedure.InformationEventHandler<string> 
                                 (InfoOccurred);
....
private void InfoOccurred(Object sender, string s)
{
    this.textBox1.Text = s + Environment.NewLine + this.textBox1.Text;
    if (this.textBox1.Text.Length > 10000)
        this.textBox1.Text = this.textBox1.Text.Remove(1000);
}

This event handling seems to be working fine. I haven’t received any cross threading issues, and overall it’s been working as expected. However, on another form I just added a similar event handler, which throws a cross-thread exception. The event fires, sending a simple class with a bit of information that I display in an InputTextBox (A custom ComponentOne control). The particular control does not have a .Invoke method, so I’m looking for alternative solutions to access it asynchronously.

So my question is, are event handlers safe to access controls on a form? If not, how do event handlers fire, and could somebody help educate me, or provide some linked information, as to how an event handler communicates with form controls? Do I need to lock the event?

  • 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-31T00:14:28+00:00Added an answer on May 31, 2026 at 12:14 am

    Controls on the UI thread may only be accessed from the UI thread – any access from other threads is bound to cause issues. You need to use InvokeRequired and BeginInvoke() to marshal an event to the right thread if it’s not already there.

    Example

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

Sidebar

Related Questions

I'm writing an application that uses a 3rd party library to process some data.
I'm writing an application that communicates through the Windows RPC mechanism with a hosted
I'm writing an android application that maintains a lot of state data...some of it
I'm currently in the process of writing an application that has quite a number
I am in the process of writing an application that processes a huge number
Dear StackOverflowers, I am in the process of writing an application that sorts a
I am writing an application that sends command line commands to a 3rd party
I'm in the process of writing a cross platform c# application that will run
I'm in the process of writing an application that interacts with a third party
I am writing a cataloging application that parses through and extracts information from files

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.