Author Topic: UI Thread Locks while calling InRange  (Read 21723 times)

servel333

  • Guest
UI Thread Locks while calling InRange
« on: June 24, 2008, 08:33:45 PM »
When I call wclnet.wclBluetoothDevice.InRange(radio) from a background thread, the UI on my application appears to lock up and is not responsive.

Computer
   Dell Optiplex 745
Language: Visual Basic 2005
Stack: Microsoft
Driver: Microsoft
   Version: 5.1.2600.2180
   C:\WINDOWS\system32\bthprops.cpl
   C:\WINDOWS\system32\DRIVERS\bthport.sys
   C:\WINDOWS\system32\DRIVERS\BTHUSB.SYS
   C:\WINDOWS\system32\fsquirt.exe
Bluetooth Dongle
   AluraTek  ABD2020
   USB Version 2.0
   VID 0x0A12
   PID 0x0001
   Bluetooth Version 2.0
   Class 2

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: UI Thread Locks while calling InRange
« Reply #1 on: June 25, 2008, 12:09:57 AM »
How do you call this?

servel333

  • Guest
Re: UI Thread Locks while calling InRange
« Reply #2 on: July 09, 2008, 10:47:14 PM »
Sorry about the delayed response to your question.

We have a dialog that continuously performs discovery for Bluetooth devices through a radio.  When discovery completes, the list is filtered for the class of device we are looking for.  Each device is then checked to determine if it is in range to prevent 'ghosting' of devices no longer detected.  After all of this is completed, the discovery process is repeated until the dialog is closed.

This all occurs in a background thread.  I noticed when the discovery process completes (wclnet.wclBluetoothDiscovery.DiscoveryComplete) it happens on the main UI thread, so I save the list of detected devices and then a background thread receives the list and processes them.  The actual call to InRange occurs in this background thread.

I have observed the UI freezing on regular intervals, and it appears to be during the background threads operation.  If I break execution during the freezing, the process is always stopped at InRange and I have verified it is being called on a background thread, not the UI thread.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: UI Thread Locks while calling InRange
« Reply #3 on: July 10, 2008, 12:00:12 AM »
It happens because the object was created in the main thread.

servel333

  • Guest
Re: UI Thread Locks while calling InRange
« Reply #4 on: July 10, 2008, 05:46:03 PM »
I set up a background thread specifically to initialize the wclnet.wclAPI and wclnet.wclBluetoothDiscovery objects, however when the code Me._library = New wclnet.wclAPI is executed in the background thread, it throws an exception.

In addition to this, it appears the exception is either disposed or set to an incorrect memory location before it gets to the Catch ex As Exception statement because it shows "Error: Cannot obtain value" when I examine it in the development environment.  Also, when I get to code that attempts to read any field in the exception object, my application simply exits without warning.

In this case I am using a BackgroundWorker to create the background thread and calling all of the above code in the DoWork() event.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: UI Thread Locks while calling InRange
« Reply #5 on: July 11, 2008, 04:24:35 PM »
Good day!

Sorry for a bit delayed answer. I have been busy with making the same app as your one for test the issue. What did I do: I created the application and in the main application's thread a created the wclAPI and called its Load method. After that I started the new thread and in it thread I created the wclBluetoothDevice and wclBluetoothRadio objects and call the InRange mthod of the new created wclBluetoothDevice instance (I used the predefined BT address and MS stack). All works fine in separeate thread.

servel333

  • Guest
Re: UI Thread Locks while calling InRange
« Reply #6 on: July 14, 2008, 11:58:38 PM »
Thank you for your help.

I need to spend some time working on other issues and I will have to come back to this later.  I'll post here again when I can provide more details about this issue, or if I find some of my code is causing this.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: UI Thread Locks while calling InRange
« Reply #7 on: July 15, 2008, 02:38:31 PM »
Of course, thank you.

 

Sitemap 1 2 3 4 5 6 7