1

Hi I have this in the main

  NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(AddressChangedCallback);
//The main also contains a form

and this method below it .

static void AddressChangedCallback(object sender, EventArgs e){
// would like to have a message box here that freezes the entire application
including  the form as mentioned above , untill OK is pressed"
}
CharithJ
  • 46,289
  • 20
  • 116
  • 131
HelloWorld_Always
  • 1,555
  • 3
  • 22
  • 32

2 Answers2

4

I'm assuming this is a WinForms application. NetworkAddressChanged event is invoked on a background thread. This is why when you display a message box from there your app stays active.

Solution 1: You need to marshal this call to your main UI thread. You can do this by using Invoke method on your main form. Define a method on the form class to show message box. Call this method using Invoke method on your main form.

Solution 2: C# / .NET messagebox is not modal

Community
  • 1
  • 1
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
0

It is called modal and modeless. Show is modeless, ShowDialog is modal. You can read more here.

CharithJ
  • 46,289
  • 20
  • 116
  • 131