So i've got some code from a GUI program that invokes a delegate via the control.invoke method and now I want to do this in a console.
This is the code:
public class upnpforwarder
{
List<INatDevice> devices = new List<INatDevice>();
public upnpforwarder()
{
//Hook into the events so you know when a router has been detected or has gone offline
NatUtility.DeviceFound += DeviceFound;
//Start searching for upnp enabled routers
NatUtility.StartDiscovery();
}
delegate void AddDeviceDelegate(INatDevice device);
delegate void RemoveDeviceDelegate(INatDevice device);
// Adding devices to the list and listbox
private void AddDevice(INatDevice device)
{
if (!devices.Contains(device))
{
devices.Add(device);
IPAddress external = device.GetExternalIP();
Mapping[] maps = device.GetAllMappings();
//complicated stuff because the library only allows to display some data via .ToString() as far as I know
string str = device.ToString();
}
}
// Event that handles a new found device
private void DeviceFound(object sender, DeviceEventArgs args)
{
//Make it thread-safe
AddDeviceDelegate AddDeviceInstance = new AddDeviceDelegate(this.AddDevice);
this.Invoke(AddDeviceInstance, new object[] { args.Device });
}
What is the best alternative method to:
this.Invoke(AddDeviceInstance, new object[] { args.Device }); ?