.NET Components for Mobility

BeginDiscoverDevices() method for multi threading search for devices

Last post 02-08-2010 5:12 PM by omarszbz. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-16-2009 6:58 AM

    • saeed
    • Not Ranked
    • Joined on 10-14-2009
    • Posts 2

    BeginDiscoverDevices() method for multi threading search for devices

    Hi anybody...

    does anybody know about BeginDiscoverDevices() method? 

     tanx all.

  • 10-16-2009 7:34 AM In reply to

    Re: BeginDiscoverDevices() method for multi threading search for devices

    I do, I wrote it... :-)
    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 10-23-2009 9:30 PM In reply to

    • veit
    • Top 10 Contributor
    • Joined on 05-16-2008
    • munich / germany
    • Posts 62

    Re: BeginDiscoverDevices() method for multi threading search for devices

     i didnĀ“t get that function either ..

  • 10-24-2009 11:54 AM In reply to

    • songu
    • Top 25 Contributor
    • Joined on 10-19-2009
    • Posts 25

    Re: BeginDiscoverDevices() method for multi threading search for devices

    It's explained here :

     Summary:
       An asynchronous version of InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean)

    Parameters:
      maxDevices:
       See InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean).

      authenticated:
        See InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean).

     remembered:
       See InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean).

     unknown:
         See InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean).

    discoverableOnly:
        See InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean).
     
       callback:
        An optional asynchronous callback, to be called when the discovery is complete.

     state:
        A user-provided object that distinguishes this particular asynchronous discovery
        request from other requests.

     Returns:
        An System.IAsyncResult that represents the asynchronous discovery, which
         could still be pending.
            public IAsyncResult BeginDiscoverDevices(int maxDevices, bool authenticated, bool remembered, bool unknown, bool discoverableOnly, AsyncCallback callback, object state);

    Did you see this ?

  • 10-25-2009 11:05 AM In reply to

    Re: BeginDiscoverDevices() method for multi threading search for devices

    There are two patterns for asynchronous operations in .NET.  I used the Begin/EndXXX+IAsyncResult one called APM (Async Programming Model) there.  It's quite flexible but a bit complex.  The other asynchronous pattern uses an event (XxxxCompleted) along with a XxxxStart() method.  I've checked into CodePlex a version of that pattern in class BluetoothComponent.  One can use it like the following.  Hopefully its a bit easier to understand.  (It's non-NETCF at the moment.  Some more work is needed for that platform, let me know if its needed).

    Public Sub DiscoDevicesAsync()
        Dim m_btco As New BluetoothComponent()
        AddHandler m_btco.DiscoverDevicesComplete, AddressOf HandleDiscoDevicesAsync
        m_btco.StartDiscoverDevices(255, True, True, True, False, Nothing)
    End Sub

    Private
    Sub HandleDiscoDevicesAsync(ByVal sender As Object, ByVal e As DiscoverDevicesEventArgs)
        If e.Cancelled Then
            Console.WriteLine("DiscoDevicesAsync cancelled.")
        ElseIf e.Error IsNot Nothing Then
           
    Console.WriteLine("DiscoDevicesAsync error: {0}.", e.Error.Message)
        Else
            Console.WriteLine("DiscoDevicesAsync found {0} devices.", e.Devices.Length)
        End If
    End Sub

    (One can even compile the BluetoothComponent class outside library assembly (e.g. in your application if it's C#) if recompiling the library it not suitable).

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
  • 11-19-2009 9:52 PM In reply to

    Re: BeginDiscoverDevices() method for multi threading search for devices

    Hi,

    I have looking into the forum for solution on methods available for the BluetoothClient to search for all bluetooth devices in the range with or without paired. I have tried DiscoverDevices(maxDevices, authenticated, remembered, unknown).

    I have tried all combination from all true to all false but still couldn't find one combination that can achieve what i want. Any other way i can search all bluetooth devices included paired and connected devices.

    Please advise. Really appreciated. Thanks.

  • 02-08-2010 5:12 PM In reply to

    Re: BeginDiscoverDevices() method for multi threading search for devices

     Hello alanjmcf...

     I don't understand your code... 

    I have problems with DiscoverDevices() method. When I callt to this method on a new Thread, this always return 0 devices. How can I use this method on a new Thread?? 

    I think that the code that you are posting will help me... But I can understand this code. Please do you can help me?... Do you have an sample?... Thank you very much!!!

Page 1 of 1 (7 items)
Copyright © 2001-2010 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.