我已经编写了一个扫描蓝牙设备的算法并将其添加到我的列表框中。现在我希望这个算法在后台永久运行。但是我的 Backgroundworker 不能正常工作。甚至我的用户界面也反应迟钝。
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
toolStripStatusLabel1->Text="Active";
toolStripProgressBar1->Value=100;
backgroundWorker1->RunWorkerAsync();
}
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
BluetoothFunction(); \\It tells me here is an Error
}
void BluetoothFunction(){
m_bt = BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);
do{
vector<wstring> vec;
int m_device_id=0;
int m_radio_id = 0;
m_radio_id++;
BluetoothGetRadioInfo(m_radio, &m_bt_info);
m_search_params.hRadio = m_radio;
::ZeroMemory(&m_device_info, sizeof(BLUETOOTH_DEVICE_INFO));
m_device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
m_bt_dev = BluetoothFindFirstDevice(&m_search_params, &m_device_info);
do{
wostringstream tmp;
++m_device_id;
//Konvertiere Byte in String
for (int i = 0; i < 6; i++) {
tmp << hex << m_device_info.Address.rgBytes [i];
if (i < 5)
tmp << L':';
}
//Verfügbarkeitsliste
vec.push_back(tmp.str());
listBox2->Items->Add(System::Runtime::InteropServices::Marshal::PtrToStringUni(IntPtr((void*) tmp.str().c_str())));
}while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));
//searchId(vec, targetId);
BluetoothFindDeviceClose(m_bt_dev);
} while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));
BluetoothFindRadioClose(m_bt);
}
我猜我的蓝牙功能参数不正确。
如果有人可以帮助我,我会很高兴。
问候