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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:11:58+00:00 2026-06-16T04:11:58+00:00

I’m using a 3rd party Library to communicate data from a 3rd party input

  • 0

I’m using a 3rd party Library to communicate data from a 3rd party input device to a Windows Form. What I am looking to do is gather input data from the device, process it and given certain conditions report back to the Windows UI thread what is going on. I do not have access to the source code of the 3rd party DLL but I do know that the main method is on a background process and I cannot communicate my findings back to the main UI thread I think because I didn’t create it?

Windows Form:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        // create instance of my listener
        MyListener listener = new MyListener(this);
        Controller controller = new Controller(listener);
   }
}

MyListener Class which extends the 3rd party class Listener:

public class MyListener : Listener
{
    public Form1 form;
    private Frame frame;

    // overloaded constructor
    public LeapListener(Form1 f)
    {
        form = f;
    }

    /// <summary>
    /// onFrame is the main method that runs every milisecond to gather relevant information 
    /// </summary>
    public override void onFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        frame = controller.frame();
     }
 }

The issue is that I can communicate back to the main UI thread from anywhere within MyListener class but I cannot communicate back from the onFrame method because it is running on a background thread. Is there anyway to get a hold of the main thread from a background thread I did not create?

I’ve tried ReportProgress, I’ve attempted to create an event on MyListener and all attempts to talk to the main UI thread from onFrame crash the application and give me invalid memory location errors.

Any help would be greatly appreciated.

  • 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-06-16T04:11:59+00:00Added an answer on June 16, 2026 at 4:11 am

    Usually, trying to access a UI object from a thread other than the one handling the UI is problematic. This is not a windows only problem, but a more general pattern.

    The usual solution is to setup some form of event propagation mechanism, which would contain the data needed to update the UI, and let the main thread handle that task.

    Let’s call the UI thread UI, and the Background thread BT.

    You could have a function which post an event to UI from BT, and then block BT until the event is processed by UI. It’s a simple system using a semaphore to block BT until UI releases it. The advantage of such a system is that it’s simple, you don’t need to handle more than one event at a time from either thread. The downside is that if events take a long time to be processed, the application would have a very poor sampling resolution from the device.
    An alternative (and better) way is to create an event queue, have BT post to it, and UI poll it to update itself. It requires a bit more work, but it’s way more resilient to UI long timing.

    For that second technique, you must establish a format for your event, setup a shared and mutex guarded queue between BT and UI, and the rest should be easy to do.

    The queue could be something like the following:

    #include <queue>
    
    
    template <typename EVENT>
    class EventQueue {
       protected:
         typedef EventQueue<EVENT> self_type;
         typedef std::queue<EVENT> queue_type;
         Mutex m_;
         queue_type q_;
         void lock(){
             // lock the mutex
         }
         void unlock(){
             // unlock the mutex
         } 
       public:
         EventQueue() {
            // initialize mutex
         }
         ~EventQueue() {
            // destroy mutex
         }
    
         void push(EVENT &e){
             lock();
             q_.push(e);
             unlock();
         }
         EVENT &pop(){
             EVENT &e;
             lock();
             e = q_.pop();
             unlock();
             return e;
         }
         int size(){
             int i;
             lock();
             i = q_.size();
             unlock();
             return i;
         }
    };
    

    This is very simple as you can see, you just have to use the template above with whatever EVENT class you need.

    I have left out the code handling the mutex, it depends on which api you want to depend on.
    As stated above, UI must only poll the queue, that is check the size of the queue, and take an event out if there’s one available. On BT side, all you need to do is to include the event push call in your MyListener class, instead of accessing the form directly.

    This method is very effective at letting both threads working together without stepping on each other toes.

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

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.