I am writing an application that works with a hardware device on the netword
through an SDK. This is designed in such a way that an object created with
the SDK will trigger events in my code, making the application
multi-threaded. Unfortunatley, this is causing a problem where my application
won't exit, and I am not sure if this is related to the thread somehow not
exiting properly. The first point where this occurs is during a device
search. Clicking a button on my UI instantiates an SDK object, and links an
event to my event handler. If I don't click the button I can exit the program
by closing the form. If I do click the button, I can close the form, but the
debugger/task manager show that the application is still running.
I appreciate any help you can give,
Regards,
Martin
The relevant code is:
public partial class Form1 : Form
{
Sirit.Driver.ConnectionDiscovery disc;
private void searchButton_Click(object sender, EventArgs e)
{
disc = new Sirit.Driver.ConnectionDiscovery();
disc.ConnectionFoundEvent += new
Sirit.Driver.ConnectionFound(ConnectionFound);
disc.findConnections();
}
public delegate void DelegateConnectionFound(object sender,
Sirit.Driver.ConnectionInfoArgs e);
public void ConnectionFound(object sender,
Sirit.Driver.ConnectionInfoArgs e)
{
if (this.textBox1.InvokeRequired){
this.textBox1.Invoke(new
DelegateConnectionFound(this.ConnectionFound),new object[]{sender,e});
}
else {
this.textBox1.Text=e.ipaddress;
disc.Stop();
disc.Dispose();
}
}
}
|