Dear,
thanks for your support! i have opened the c++ but i must study them (my knoledge of c++ is poor..).
I found in c# two ways :
1) Application.DoEvenst() exists only in Windows Form, in WPF there isn't, but i found this and it works:
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, Flags = System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
2) I have notice when i use lambda expression to assign OnDiscoveryComplete it is called when i Unload the wclApi with these approach i can:
(is not elegant but it works...)
private wclBluetoothDevices EnumerateSync(bool discover = false)
{
wcl.wclAPI api = new wclAPI();
api.Load();
wclBluetoothDevices blueToothDevices = new wclBluetoothDevices();
wcl.wclBluetoothRadio radio = GetSelectedRadio();
bool stop = false;
var discovery = new wcl.wclBluetoothDiscovery();
discovery.OnDiscoveryComplete += new wcl.wclBluetoothDiscoveryCompleteEventHandler((s, ea) =>
{
for (uint y = 0; y < ((wclBluetoothDiscoveryCompleteEventArgs)ea).Devices.Count; y++)
{
blueToothDevices.Add(((wclBluetoothDiscoveryCompleteEventArgs)ea).Devices[y]);
}
stop = true;
}
);
if (discover == true)
discovery.Discovery(radio, 5, false); //search in range
else
discovery.Discovery(radio, 0, true); //only pair
int x = 0;
int waitSecondsLimit = 0;
if (discover == true)
waitSecondsLimit = 50; //search in range for 5sec
else
waitSecondsLimit = 10; //only pair for 1 sec
while (stop == false)
{
api.Unload();
api.Dispose();
api = null;
Thread.Sleep(100);
if (x++ >= waitSecondsLimit)
{
//terminate..
break;
}
}
return blueToothDevices;
}