Author Topic: OPPClient and multiple threads  (Read 24798 times)

alexey_gusev

  • Guest
Re: OPPClient and multiple threads
« Reply #15 on: June 08, 2009, 06:15:03 PM »
oops, I will reinstall it to ensure, because I don't see it right now anywhere

alexey_gusev

  • Guest
Re: OPPClient and multiple threads
« Reply #16 on: June 08, 2009, 06:22:30 PM »
hmm, that's either just me or the zip file doesn't contain that folder at all. I've reinstalled the exe (WCL_Personal_NET.exe) and don't see anything like *thread* in any demo folders

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #17 on: June 08, 2009, 10:54:15 PM »
Ooops. My mistake. I am really sorry. I have created the samples but didn't modify installer script to add samples to Setup. Will fix it tomorrow and reupload, or upload a sample here.

alexey_gusev

  • Guest
Re: OPPClient and multiple threads
« Reply #18 on: June 08, 2009, 10:58:58 PM »
ok, no probs :)

while we're on it, could you please fix small typo in TIMEOUT error returned from wclErrors.GetErrorMesage() ? right now it reads "Timout" (ie  "e" is missing)

Thanks,
Alex

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #19 on: June 09, 2009, 01:09:22 AM »
Fixed, thanks :)

Cuningan

  • Guest
Re: OPPClient and multiple threads
« Reply #20 on: June 13, 2009, 03:16:39 PM »
Hello Mike and Alexey.

Please notify here when the package with the example will be terminated because i am interested in it.

ehartwell

  • Guest
Re: OPPClient and multiple threads
« Reply #21 on: June 25, 2009, 06:59:22 PM »
I'd also love to see the sample.

Thanks to this post, I just finished debugging the same problem in a WPF .NET application. I;m using the Disconnected event triggers a retry timer that keeps retrying the connection until the device is back in range. The wclClient object was originally created in the UI thread.

When I used System.Timers.Timer to call Connect(), the device was connecting, but the Connected event was never being raised. I finally changed the code to use System.Windows.Threading.DisapatchTimer, which runs in the UI thread instead of its own worker thread, and now the Connected event is raised and caught.

The corresponding UI thread timer for Windows Forms applications is System.Windows.Forms.Timer.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #22 on: July 02, 2009, 01:53:02 PM »
Here is very simple demo app. It processes only 2 events (OnConnect and OnDisconnect) but I think you will get the idea.

[attachment deleted by admin]

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #23 on: July 03, 2009, 12:23:07 AM »
Updated sample. Now it sends the file. How to use:

Click "Select" to select the file. Clieck "Discover" to find the devices. Select device and click "Send". Wait when "Disconnected" appears. Do not click "Send" when already sending.

Very simple but easy to unerstand sample.

[attachment deleted by admin]

ehartwell

  • Guest
Re: OPPClient and multiple threads
« Reply #24 on: March 04, 2010, 03:39:51 PM »
I have a C#/WPF application using WCL quite successfully. We found that WCL events are missed unless WCL runs in WPF's UI thread. Up to now this has meant we need to use System.Windows.Threading.DispatchTimer and not System.Timers.Timer.

We've just found an issue, where Bluetooth send and receive apparently blocks while the application is busy. We've already moved as much of the processing code into background threads as we can; what's left is the unavoidable WPF overhead for things like DataView updates.

The OPPThread sample works great (thanks!), but at its core it has an Application.DoEvents() loop.  In its wisdom, Microsoft decided DoEvents really *is* evil, and designed WPF without a DoEvents API.

Since WPF does all its UI handling on a single thread, it doesn't let you monitor Windows messages on a background thread. There are a few workarounds posted on the web, but they all come with scary warnings about bad effects and application instability.

So, my questions are:
  • Is there a good way to use WCL in .NET without using a DoEvents() loop?
  • Could this be causing the "Internal driver error" I reported in a different thread?



Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #25 on: March 04, 2010, 03:43:22 PM »
Hi,

1. Yes of course. Run it in separate thread with separate windows message loop.
2. It may be.

ehartwell

  • Guest
Re: OPPClient and multiple threads
« Reply #26 on: March 04, 2010, 03:47:57 PM »
Wow! Talk about quick response! I'll see what I can do, but as I said, WPF doesn't want to share its Windows message loop, so we may have to resort to interop. I'll let you know what happens.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3520
  • Karma: 1000
    • Wireless Communication Libraries
Re: OPPClient and multiple threads
« Reply #27 on: March 04, 2010, 03:53:19 PM »
Yes, that may need some work. unfortunatly there is no other good way to synchronize different threads except using windows messages. And threads must be synchronized to be sure that WCL events will fire in the same thread which called method. It is not WCL limitation but it was developed so to make it working good with .NET, VCL, COM and MFC. As you may know .NET does not allow to fire (catch) events with different threads (as well as VCL/MFC).

The other idea it to try move some job from your main thread to separate one and have WCL in main thread.

P.S. That's why I do not like .NET. UI development is great and simple, but as you start making something specified it become to be a nightmare.

 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14