当前位置: 首页>>代码示例>>C#>>正文


C# BluetoothClient.Dispose方法代码示例

本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient.Dispose方法的具体用法?C# BluetoothClient.Dispose怎么用?C# BluetoothClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InTheHand.Net.Sockets.BluetoothClient的用法示例。


在下文中一共展示了BluetoothClient.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BluetoothConnect

        void BluetoothConnect()
        {
            string androidTabletMAC = "68:05:71:AA:2B:C7"; // The MAC address of my phone, lets assume we know it

            BluetoothAddress addr = BluetoothAddress.Parse(androidTabletMAC);
            //var btEndpoint = new BluetoothEndPoint(addr, 1600);
            var btClient = new BluetoothClient();
            //btClient.Connect(btEndpoint);

            Stream peerStream = btClient.GetStream();

            StreamWriter sw = new StreamWriter(peerStream);
            sw.WriteLine("Hello World");
            sw.Flush();
            sw.Close();

            btClient.Close();
            btClient.Dispose();
               // btEndpoint = null;
        }
开发者ID:AstaraelWeeper,项目名称:MainServerPlayer,代码行数:20,代码来源:Bluetooth.cs

示例2: button_search_Click

        //Search
        private void button_search_Click(object sender, EventArgs e)
        {
            try
            {
                this.label_status.Text = "Please wait... searching for wockets";
                this.Refresh();
                this.button_search.Enabled = false;

                this.dataGridView1.Rows.Clear();
                this.macaddresses.Clear();
                bluetoothlist.Clear();
                int wocketCount = 0;

                if (BluetoothRadio.PrimaryRadio.Mode != RadioMode.Connectable)
                {
                    BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
                }
                BluetoothClient btc = new BluetoothClient();

                label_status.Text = "Searching for wockets...";
                Application.DoEvents();

                devices = btc.DiscoverDevices(60, true, true, true);

                for (int i = 0; (i < devices.Length); i++)
                {
                    //if the device is a wocket
                    if (((devices[i].DeviceName.IndexOf("Wocket") >= 0)
                        || (devices[i].DeviceName.IndexOf("WKT") >= 0)
                        || (devices[i].DeviceName.IndexOf("FireFly") >= 0)
                        || (devices[i].DeviceName.IndexOf("00:06:66") >= 0)
                        && (wocketCount < 100)))
                    {
                        string hex = "";
                        hex = devices[i].DeviceAddress.ToString();

                        System.Threading.Thread.Sleep(1000);

                        if (this.macaddresses.IndexOf(hex) < 0)
                        {
                            int row = this.dataGridView1.Rows.Add();

                            this.dataGridView1.Rows[row].Cells[0].Value = devices[i].DeviceName;
                            this.dataGridView1.Rows[row].Cells[1].Value = hex;
                            this.dataGridView1.Rows[row].Cells[2].Value = "Not tested";
                            this.dataGridView1.Rows[row].Cells[3].Value = "Not tested";

                            macaddresses.Add(hex);
                            bluetoothlist.Add(devices[i]);

                            System.Threading.Thread.Sleep(1000);

                        }

                        wocketCount++;
                    }
                }

                btc.Dispose();
                btc.Close();

                if (this.dataGridView1.Rows.Count > 0)
                {
                    this.button_test.Enabled = true;
                    this.button_settings.Enabled = true;
                }

                label_status.Text = "Waiting for wocket...";

            }
            catch
            {
                label_status.Text = "BT module not responding.";
            }

            this.button_search.Enabled = true;
        }
开发者ID:katadam,项目名称:wockets,代码行数:78,代码来源:Form4.cs

示例3: button_search_Click

        private void button_search_Click(object sender, EventArgs e)
        {
            this.label_status.Text = "Please wait... searching for wockets";
            this.Refresh();
            this.button_search.Enabled = false;
            this.listBox1.Items.Clear();
            BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
            BluetoothClient btc = new BluetoothClient();

            devices = btc.DiscoverDevices(60, false, false, true);
            int wocketCount = 0;
            for (int i = 0; (i < devices.Length); i++)
            {
                //if the device is a wocket
                if (((devices[i].DeviceName.IndexOf("Wocket") >= 0)
                    || (devices[i].DeviceName.IndexOf("WKT") >= 0)
                    || (devices[i].DeviceName.IndexOf("FireFly") >= 0)
                    || (devices[i].DeviceName.IndexOf("00:06:66") >= 0))
                    && (wocketCount < 100))
                {
                    string hex = "";
                    hex = devices[i].DeviceAddress.ToString();
                    if (this.listBox1.Items.IndexOf(hex) < 0)
                    {
                        this.listBox1.Items.Add(devices[i].DeviceName + " (" + hex + ")");
                        macaddresses.Add(hex);
                    }
                    wocketCount++;
                }
            }
            btc.Dispose();
            btc.Close();

            if (this.listBox1.Items.Count > 0)
                this.button_configure.Enabled = true;
            this.button_search.Enabled = true;
        }
开发者ID:katadam,项目名称:wockets,代码行数:37,代码来源:Form1.cs

示例4: SendZip


//.........这里部分代码省略.........
                                {
                                    this.Status = "Too big file!";
                                    MessageBox.Show("Too big file!");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogEvent(true, "MainViewModel.SendZip 207 Exception = {0} , \nStack = {1}", ex.Message, ex.StackTrace);
                            lastEx = ex;
                        }
                        finally
                        {
                            //if (bluetoothClient != null)
                            //{
                            //    //bluetoothStream.Flush();
                            //    //bluetoothStream.Close();

                            //    bluetoothClient.Close();
                            //    bluetoothClient.Dispose();
                            //}
                        }
                    }

                    Logger.LogEvent(true, "MainViewModel.SendZip 208");

                    this.StopTimer(aTimer);
                    //if (bluetoothStream != null)
                    //{
                    //    bluetoothStream.Flush();
                    //    bluetoothStream.Close();
                    //}

                    if (bluetoothClient != null)
                    {
                        Logger.LogEvent(true, "MainViewModel.SendZip 209");

                        bluetoothClient.Close();
                        bluetoothClient.Dispose();
                        bluetoothClient = null;
                    }

                    Logger.LogEvent(true, "MainViewModel.SendZip 210");
                }
            }).ContinueWith(taskState =>
            {
                Logger.LogEvent(true, "MainViewModel.SendZip 211");

                this.IsScanning = false;

                if (success)
                {
                    this.Status = string.Format("File \"{0}\" has been transferred to {1}!", Path.GetFileNameWithoutExtension(this.lastZipPath) + ".lmu", this.selectedDevice.Name);
                    this.ClearAfterSendOrCancel();
                }
                else if (!this.wasCanceled)
                {
                    this.Status = "Form transfering failed.";

                    Logger.LogEvent(true, "MainViewModel.SendZip 212 lastEx: {0}", lastEx == null ? "IsNULL" : "Not NULL");

                    if (lastEx != null)
                    {
                        if (lastEx is SocketException)
                        {
                            var socketEx = (SocketException)lastEx;

                            BluetoothRadio.PrimaryRadio.Mode = RadioMode.PowerOff;

                            if (socketEx.SocketErrorCode == SocketError.AddressNotAvailable || socketEx.SocketErrorCode == SocketError.TimedOut)
                            {
                                MessageBox.Show("Selected bluetooth device is not available. Please press \"App Update\" button on an appropriate device before sending forms.", "Destination device is not reachable.",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                            else if (socketEx.SocketErrorCode == SocketError.InvalidArgument || socketEx.SocketErrorCode == SocketError.Shutdown)
                            {
                                MessageBox.Show("Try one of next solutions:\n- Try to restart the application\n- Unpair devices in settings (for both devices) and pair them again.\n",
                                    "Bluetooth connection problem.", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            else// if (lastEx.Message.Contains("invalid argument was supplied")) // (lastEx as SocketException).SocketErrorCode == SocketError.Shutdown
                            {
                                MessageBox.Show("Try one of next solutions:\n- Try to restart the application;\n- Unpair devices in settings (for both devices) and pair them again;\n- Go to Start > Type services.msc > Services Local > Then scroll down the list till you see 'Bluetooth Support Service' > Right click on it and then Stop the process and then start it up again;\n- Update bluetooth drivers;",
                                    "Bluetooth connection problem.", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }

                        Logger.LogEvent(true, "MainViewModel.SendZip 213");

                        this.AddExceptionToLog(lastEx);
                    }

                    this.SelectedDeviceIndex = -1;
                }

                Logger.LogEvent(true, "MainViewModel.SendZip 214");

            }, TaskScheduler.FromCurrentSynchronizationContext());

            Logger.LogEvent(true, "MainViewModel.SendZip 215");
        }
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia-LaptopTransfer,代码行数:101,代码来源:MainViewModel.cs

示例5: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            this.label2.Text = "Searching... please wait";
            this.label2.Update();
            try
            {
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
                BluetoothClient btc = new BluetoothClient();

                devices = btc.DiscoverDevices(60, false, true, true);

                for (int i = 0; (i < devices.Length); i++)
                {
                    //if the device is a wocket
                    if (((devices[i].DeviceName.IndexOf("Wocket") >= 0)
                        || (devices[i].DeviceName.IndexOf("WKT") >= 0)
                        || (devices[i].DeviceName.IndexOf("FireFly") >= 0)
                        || (devices[i].DeviceName.IndexOf("0006660") >= 0)
                        && (wocketCount < 100)))
                    {
                        string hex = "";
                        hex = devices[i].DeviceAddress.ToString();

                        #region Commented
                        // if (this.WocketsList_Box.Items.IndexOf(hex) < 0)
                        //{
                        //    this.WocketsList_Box.Items.Add(devices[i].DeviceName + " (" + hex + ")");
                        //macaddresses.Add(hex);
                        //}
                        #endregion Commented

                        this.listBox1.Items.Add(hex);
                        bluetoothlist.Add(hex, devices[i]);

                        wocketCount++;
                    }
                }

                btc.Dispose();
                btc.Close();
            }
            catch
            {
                MessageBox.Show("Cannot connect: please check your Bluetooth radio is plugged in and active");
                Environment.Exit(0);
            }
        }
开发者ID:katadam,项目名称:wockets,代码行数:48,代码来源:Form1.cs

示例6: receive_file

        public override void receive_file(String devicename, String bluid, int not)
        {
            try
            {
                _stopwatch.Start();
                scan_transfer_speed();                

                _bluetooth_guid = Guid.Parse(bluid);
                _bluetooth_listener = new BluetoothListener(_bluetooth_guid);
                _bluetooth_listener.Start();

                _bluetooth_client = _bluetooth_listener.AcceptBluetoothClient();
                _netstream = _bluetooth_client.GetStream();

                _filestream = new FileStream(this.filepath, FileMode.Create, FileAccess.ReadWrite);

                int length;
                _buffer = new byte[65000];
                
                while ((length = _netstream.Read(_buffer, 0, _buffer.Length)) != 0)
                {
                    while (_writing) { }

                    _count_received_bytes += length;

                    _filestream.Write(_buffer, 0, length);
                }

                _timer_ts.Close();
                _stopwatch.Stop();

                int _transferspeed = _count_received_bytes / 1024;
                _message = format_message(_stopwatch.Elapsed, "Transferspeed", _transferspeed.ToString(), "kB/s");
                this.callback.on_transfer_speed_change(_message, this.results);
                this.main_view.text_to_logs(_message);

                _filestream.Dispose();
                _filestream.Close();

                _netstream.Dispose();
                _netstream.Close();

                _bluetooth_client.Dispose();
                _bluetooth_client.Close();

                _bluetooth_listener.Stop();

                _message = format_message(_stopwatch.Elapsed, "File Transfer", "OK", this.filepath);
                this.callback.on_file_received(_message, this.results);
                this.main_view.text_to_logs(_message);
            }
            catch (Exception e)
            {
                append_error_tolog(e, _stopwatch.Elapsed, devicename);
            }
        }               
开发者ID:StabilityofWT,项目名称:Stability-Monitor,代码行数:56,代码来源:Bluetooth_agent.cs

示例7: send_file

        public override void send_file(String devicename, String bluid, int not)
        {
            try
            {
                _stopwatch.Start();

                _bluetooth_client = new BluetoothClient();

                BluetoothDeviceInfo[] devinfos = _bluetooth_client.DiscoverDevices();

                foreach (var device in devinfos)
                {
                    if (device.DeviceName == devicename)
                    {
                        _bluetooth_address = device.DeviceAddress;
                        break;
                    }
                }

                _bluetooth_guid = Guid.Parse(bluid);

                _bluetooth_client.Connect(_bluetooth_address, _bluetooth_guid);

                _netstream = _bluetooth_client.GetStream();

                byte[] dataToSend = File.ReadAllBytes(this.filepath);

                _netstream.Write(dataToSend, 0, dataToSend.Length);
                _netstream.Flush();

                _netstream.Dispose();
                _netstream.Close();

                _bluetooth_client.Dispose();
                _bluetooth_client.Close();

                _message = format_message(_stopwatch.Elapsed, "File Transfer", "OK", this.filepath);
                this.callback.on_file_received(_message, this.results);
                this.main_view.text_to_logs(_message);

                _stopwatch.Stop();
            }
            catch (Exception e)
            {
                append_error_tolog(e, _stopwatch.Elapsed, devicename);
            }
        }
开发者ID:StabilityofWT,项目名称:Stability-Monitor,代码行数:47,代码来源:Bluetooth_agent.cs


注:本文中的InTheHand.Net.Sockets.BluetoothClient.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。