In my application (Windows 7 Prof, Xamarin Studio V 5.10.1 build 6) I try to open a serial port. If this port is not available, I try to send a dialog message to the user and then to exit the program with the following code, which unfortunately doesn't terminate the application:
enter code here
using System;
using Gtk;
using Pango; // benötigt für Font-Operationen
using System.Diagnostics; // benötigt für "Process.Start (...)"
using System.IO.Ports; // benötigt für serielle Schnittstelle
using System.IO; // benötigt für IOException
public partial class MainWindow : Gtk.Window
{
// Globale Variable der Klasse
// ---------------------------
bool valret = true, wahl = true;
SerialPort sPort;
....
// Initialisierung der seriellen Schnittstelle
// -------------------------------------------
try { sPort.Open(); }
catch {
MessageDialog md = new MessageDialog (null,
DialogFlags.DestroyWithParent,
MessageType.Error,
ButtonsType.Close, "Serial IF nicht vorhanden");
int result = md.Run ();
Application.Quit ();
md.Destroy ();
}
Neither the Main window is closed nor is the *.exe program terminated. Instead, the program continues to run with errors due to the following wrong access to sPort functions not being available.
Which code is recommended to do the job? Thanks a lot for any comments!