Exemplo n.º 1
0
 public static void SomeMethod()
 {
     Threading.Thread t = new Threading.Thread(() =>
     {
         try {
             while (true)
             {
                 dynamic server = new NamedPipeServerStream("Closer", PipeDirection.InOut, -1);
                 server.WaitForConnection();
                 if (!server.IsConnected)
                 {
                     return;
                 }
                 dynamic reader  = new IO.StreamReader(server);
                 dynamic casetxt = reader.ReadToEnd();
                 server.Close();
                 RootForm.Invoke(() =>
                 {
                     if (casetxt == "End")
                     {
                         System.Environment.Exit(0);
                     }
                 });
             }
         } catch (Exception ex) {
             // try/catch required in all child threads as error silently ends app.
             // log it...
         }
     });
     t.IsBackground = true;
     t.Name         = "EnderListener";
     t.Start();
 }
Exemplo n.º 2
0
 private void Form1_Load(object sender, System.EventArgs e)
 {
     // Dim s As New InTheHand.Windows.Forms.SelectBluetoothDeviceDialog()
     // s.ForceAuthentication = True
     // s.ShowAuthenticated = True
     // s.ShowRemembered = True
     // s.ShowUnknown = True
     // s.ShowDialog()
     System.Threading.Thread t1;
     t1 = new Threading.Thread(new System.EventHandler(this.receiveLoop));
     t1.Start();
     btClient = new BluetoothClient();
     BluetoothDeviceInfo[] bdi = btClient.DiscoverDevices();
     cboDevices.DataSource    = bdi;
     cboDevices.DisplayMember = "DeviceName";
 }