i will start with saying that i don't know c# very good and it's probable a very simple solution.
what i want to achieve is when network status is changed i want to change a label
i found out how to triger and event when network is changed
using System.Net.NetworkInformation;
private void Form1_Load(object sender, EventArgs e)
{
NetworkChange.NetworkAddressChanged += new
NetworkAddressChangedEventHandler(AddressChangedCallback);
}
public void AddressChangedCallback(object sender, EventArgs e)
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface n in adapters)
{
label1.Text = "bla bla";
}
}
now when i disabled a nic card i can see that AddressChangedCallback is called but then VS is stoping or an error "Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on."
what i need to change in my code in order to change the label from AddressChangedCallback
Thanks :)