I have a problem with the obexListener object, when executing the line:
ObexListenerContext context = obexListener.GetContext ();
That is waiting for the file that is sent by bluetooth and the program does not respond until it receives the file. But what happens if no file is sent? then it waits indefinitely and I have no way to stop the program.
In what way can I implement a waiting time and if nothing is received after that time then the operation is canceled?
I leave the code: Thanks.
ObexListener obexListener = new ObexListener(ObexTransport.Bluetooth);
BluetoothWin32Authentication bluetoothWin32 = new BluetoothWin32Authentication(codigo);
Guid guid = new Guid(BluetoothService.SerialPort.ToString());
obexListener.Start();
if (obexListener.IsListening)
{
timer2.Start();
ObexListenerContext context = obexListener.GetContext();
context.Request.WriteFile(archivoBluetooth);
obexListener.Close();
}
private void codigo(object sender, BluetoothWin32AuthenticationEventArgs e)
{
if (!obexListener.Authenticate)
{
switch (MessageBox.Show("Desea vincular el dispositivo: " + e.Device.DeviceName.ToString(), "Atención", MessageBoxButtons.YesNo))
{
case DialogResult.Yes:
e.Confirm = true;
break;
case DialogResult.No:
e.Confirm = false;
break;
}
}
else
{
switch (MessageBox.Show("Desea vincular el dispositivo: " + e.Device.DeviceName.ToString(), "Atención", MessageBoxButtons.YesNo))
{
case DialogResult.Yes:
e.Confirm = true;
MessageBox.Show("Bienvenido Nuevamente!");
break;
case DialogResult.No:
e.Confirm = false;
break;
}
}
}