I have a common comms library that i have written to communicate with our hardware over TCP/IP
The common library allows both the clients application and our engineer tool to share common code. The common library runs threads that need to return data back to forms.
I have some working code but I feel that there must be an easier way to do it.
This is a simplified version of what i have...
namespace EngineerTool
{
public delegate void DelegateSearchFinished();
public partial class MainForm : Form
{
public DelegateSearchFinished d_SearchFinished;
Discover discovery;
public MainForm()
{
InitializeComponent();
discovery = new Discover(this.FinishedSearchInvoke);
d_SearchFinished = new DelegateSearchFinished(this.FinishedSearch);
discovery.Start();
}
public void FinishedSearchInvoke()
{
this.Invoke(this.d_SearchFinished, new Object[] {});
}
public void FinishedSearch()
{
// Search has finished here!
}
}
}
namespace DiscoveryTool
{
public delegate void DelegateSearchFinished();
public class Discover
{
DelegateSearchFinished _callFinished;
public Discover(DelegateSearchFinished callFinished)
{
_callFinished = callFinished;
}
public void Start()
{
// starts thread and stuff
}
public void ThreadWorker()
{
_callFinished();
}
}
}