Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have made an alarm system. What it does is that any system on the network broadcasts an UDP message on the network and other clients on the network receive that message and display it.
What I want to do is that, when the main form receives an alarm message it would show an other form with the message and if the computer which broadcasted the message sends a cancel alarm message the second form (showing alert message)should be closed on all the clients.
C#
FrmAlertScreen frm = new FrmAlertScreen();

if (Convert.ToBoolean(alarm))//Set alarm to ring.
{
       status = "Ringing";
       RingAlarm = true;
       if (IsLocaly == false)//Alarm is not sent by local system then don't show alert screen.
       {
           frm.Show ();
       }

       IsLocaly = false;
}
else //Alram goes silent.
{
     
       status = "Silent";
       RingAlarm = false;
       frm.Hide() ;
       IsLocaly = false;
}

Problem with this code is that frm.show() makes the message form to go into wait probably because it was running in background thread.
Posted
v2

1 solution

All forms should be handled by the application's main thread. Do the communication in another thread. But as soon as the GUI needs to show something, let the main thread do it.
That's what Control.InvokeRequired[^] and Control.Invoke[^] are for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900