Hi, first sorry for my english XD.
I am developing an application in C# with .NET using the last version of 32feet.NET library. My application may send files to multiple cell-phones at the same time. To do it i have a thread with the discover devices searching code (i use the backgroudWorker class for this), and when i have all the discovered devices in a list, i create a new thread (with an another backgroundWorker) for each device in the list. Each created thread runs the send code... But it does not work properly because it only send´s data to the first discovered device.
I hope you can help me, and i post my searching and sending code for this:
// Search Code
public static InTheHand.Net.Sockets.BluetoothDeviceInfo[ BusquedaDispositivos(BackgroundWorker worker, DoWorkEventArgs e)
{
InTheHand.Net.Sockets.BluetoothClient btClient = new InTheHand.Net.Sockets.BluetoothClient();
InTheHand.Net.Sockets.BluetoothDeviceInfo[ bdi = btClient.DiscoverDevices(15);
return bdi;
}
// Send Code
public RespuestaEnvioOBEX EnvioFichero(BackgroundWorker worker, DoWorkEventArgs e)
{
string Fichero = "C:\\Proyectos\\proyectoMarketingBluetooth\\EnvioFicheros\\Prueba.txt";
try
{
InTheHand.Net.ObexWebRequest request = new InTheHand.Net.ObexWebRequest(((DatosEnvioOBEX)e.Argument).Uri);
request.ReadFile(Fichero);
InTheHand.Net.ObexWebResponse response = (InTheHand.Net.ObexWebResponse)request.GetResponse();
response.Close();
RespuestaEnvioOBEX respuesta = new RespuestaEnvioOBEX(response, ((DatosEnvioOBEX)e.Argument).Mac, ((DatosEnvioOBEX) e.Argument).NombreDispositivo, null);
return respuesta;
}
catch (Exception ex)
{
DatosEnvioOBEX datos = (DatosEnvioOBEX)e.Argument;
RespuestaEnvioOBEX respuesta = new RespuestaEnvioOBEX(null, ((DatosEnvioOBEX)e.Argument).Mac, ((DatosEnvioOBEX)e.Argument).NombreDispositivo, ex.Message);
return respuesta;
}
// This send Code is invoqued from this another code
private void EnvioFicherosADispositivos()
{
int i = 0;
foreach(InTheHand.Net.Sockets.BluetoothDeviceInfo dispositivo in this.dispositivosEncontrados)
{
i++;
Uri theuri = new Uri("obex://" + dispositivo.DeviceAddress.ToString() + "/" + System.IO.Path.GetFileName (Configuracion.NombreFichero));
dispositivo.DeviceAddress.ToString(), dispositivo.DeviceName,
Convert.ToInt32(dispositivo.ClassOfDevice.Device));
this.configurarBakcParaCadaDispositivo(new DatosEnvioOBEX(theuri, dispositivo.DeviceAddress.ToString(),
dispositivo.DeviceName, Convert.ToInt32(dispositivo.ClassOfDevice.Device)));
}
this.recorridaListaCompleta = true;
MessageBox.Show("Envio finalizado");
}
private void configurarBakcParaCadaDispositivo(DatosEnvioOBEX vDatosEnvio)
{
BackgroundWorker backgroundWorkerEnvio = new BackgroundWorker();
backgroundWorkersEnvio.Add(backgroundWorkerEnvio);
backgroundWorkersEnvio[backgroundWorkersEnvio.Count - 1].WorkerSupportsCancellation = true;
backgroundWorkersEnvio[backgroundWorkersEnvio.Count - 1].DoWork += new
DoWorkEventHandler(backgroundWorkerEnvio_DoWork);
backgroundWorkersEnvio[backgroundWorkersEnvio.Count - 1].RunWorkerCompleted += new
RunWorkerCompletedEventHandler(backgroundWorkerEnvio_RunWorkerCompleted);
backgroundWorkersEnvio[backgroundWorkersEnvio.Count - 1].RunWorkerAsync(vDatosEnvio);
}
Very thanks!