Sunday 15 April 2012

c# - End Program After MessageBox is Closed -


At the beginning of my program, I am checking to see if I started a connection with the device on COM6 Can i If the device is not found, then I want to display a message box and then complete the program.

; } Hold {MessageBox.Show ("No Device Detected", MessageBoxButtons.OK, MessageBoxIcon.Error)} Application.EnableVisualStyles (); Application.SetCompatibleRenderingDefault (wrong); Application.Run (New Form 1 ());

When I try a message application. EXT (); After the message box command, the message box is displayed correctly when no device is found, but when I close the message box, Form 1 still opens, but is completely frozen and I Do not close it or click on any button, so that I should give an error because the device is not connected.

I'm just looking for the remote to kill the program after the message box is displayed. Thank you.

Solution: After returning MessageBox, the returns; left after using the method, like I wanted when this device was not plugged. However, when the device was plugged in, there were problems reading after testing. It was something I had not searched for before, but it was a simple improvement. Here's my fully working code:

  try {test = new reader ("COM6"); Test.Dispose (); // had to be settled so that I could connect later in the program. Simple fix} Hold {MessageBox.Show ("No Device Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error) Return; } Applications. Enabledview style (); Application.SetCompatibleTextRenderingDefault (wrong); Application.Run (New Form 1 ());    

Since it is in the main () routine, just return :

  Try {Reader = New Reader ("COM6"); } Hold {Messagebox.Show ("No Device Detected", MessageBoxButtons.OK, MessageBoxIcon.Error) Return; // will exit the program} application. Enabledview style (); // ... return to other code ..   

here will exit the process.

No comments:

Post a Comment