Author Topic: WCL in console application  (Read 2816 times)

badbod99

  • Guest
WCL in console application
« on: June 30, 2009, 04:47:51 PM »
I've created a console application trying to use the Discovery function, however I am not receiving the events OnDiscoveryStarted and OnDiscoveryComplete.  I have blocked the thread using something like:

while (_scanning) Thread.Sleep(1);

Using dotNet events this would not normally cause an issue, but I assume there is some internal messaging going on which is not managing to callback.

Is it possible to use WCL in a console application?  How can I get around this issue?

Thanks

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: WCL in console application
« Reply #1 on: June 30, 2009, 06:04:57 PM »
Hi,

it was discussed lots of time on this forum. WCL uses windows messages internally to delivery events between threads and to get notifications from low-leve drivers. Your application (even console) must have message loop.

badbod99

  • Guest
Re: WCL in console application
« Reply #2 on: June 30, 2009, 06:52:49 PM »
This is what I thought, but after considerable searching I couldn't find a clear answer, most seemed to be about threading.  For example... A search on the forum for "console" returned no results.

Should it work with a Windows service in that case?  I assume not, unless I use a hidden window of some sort.  Do you have any example of this?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: WCL in console application
« Reply #3 on: July 01, 2009, 09:52:25 AM »
It works in any application which has message loop. I have no sample for that right now but try to write one later.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: WCL in console application
« Reply #4 on: July 02, 2009, 05:16:13 PM »
Please, take a look at this article: http://msdn.microsoft.com/en-us/magazine/cc163417.aspx
It describes how to add message loop to any application (especially to console one)

Russian version: http://msdn.microsoft.com/ru-ru/magazine/cc163417.aspx

badbod99

  • Guest
Re: WCL in console application
« Reply #5 on: July 02, 2009, 05:19:09 PM »
That's great, thanks.

Might be a good idea to integrate this logic directly into your .Net wrapper, would make it a bit more simple to use.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3053
  • Karma: 1000
    • Soft Service Company
Re: WCL in console application
« Reply #6 on: July 02, 2009, 05:38:41 PM »
I agree with you and will try to do so.

 

Sitemap 1 2 3 4 5 6 7 8 9