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.