private static void Bd_ConnectionStatusChanged(um.BluetoothDevice sender, object args)
 {
     Console.WriteLine("Connection status changed!");
     if (sender.ConnectionStatus == um.BluetoothConnectionStatus.Connected)
     {
         Console.WriteLine("We have not connected before, opening pop up");
         System.Diagnostics.Process.Start(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "BluetoothUI.exe"), "-show");
     }
 }
        static async Task MainLoop()
        {
            try
            {
                Console.WriteLine("Getting program configuration...");
                RegistryKey reg1 = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\AppleBluetoothUI");
                string      temp;
                temp = reg1.GetValue("AssetLocation").ToString();
                temp = reg1.GetValue("ButtonText").ToString();
                temp = reg1.GetValue("DeviceAddress").ToString();
                temp = reg1.GetValue("DeviceName").ToString();
                temp = reg1.GetValue("StaticText").ToString();
                temp = reg1.GetValue("UsingImage").ToString();
                temp = reg1.GetValue("TemplateName").ToString();
                temp = reg1.GetValue("UsingStaticText").ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine("Please pair a bluetooth device!");
                MessageBox.Show("Please pair a bluetooth device or check your configurations.");
                System.Diagnostics.Process.Start("BluetoothUI.exe");
                Environment.Exit(-1);
            }

            //Main registry variable
            RegistryKey reg = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\AppleBluetoothUI", true);

            //Create the bluetooth device variable
            um.BluetoothDevice bd = await um.BluetoothDevice.FromBluetoothAddressAsync(Convert.ToUInt64(reg.GetValue("DeviceAddress")));

            //Create event handler
            bd.ConnectionStatusChanged += Bd_ConnectionStatusChanged;

            //Main loop
            while (true)
            {
                Console.WriteLine("Running program, this message will keep repeating itself so the program does not exit.");
                Thread.Sleep(500);
            }
        }