我正在用 C# 开发代码以与自定义蓝牙设备进行通信。我用来连接设备的代码基本上如下所示:
BluetoothDeviceInfo device_info = new BluetoothDeviceInfo(BluetoothAddress.Parse(address_str));
try
{
BluetoothClient connection = new BluetoothClient();
connection.Connect(device_info.DeviceAddress, BluetoothService.SerialPort);
if (connection.Connected)
{
...
}
else
{
...
}
}
catch (Exception e)
{
...
}
问题是 Connect 调用经常在大约 5 秒后超时。有时它会在大约 3 秒后成功,我有理由相信,如果我允许更多时间,可以成功建立连接。但是,我没有将这个超时设置为 5 秒。我只是调用 Connect 方法,它在某个时候超时。
有没有办法在 32 英尺的某个地方配置这个超时?