×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    1

    How do I solve producer-consumer case in a blocking way in Windows Phone?

    I work on the application that is kind of a remote controller for a PC (allows to manipulate cursor and keyboard). You can actually see touchpad in the application. When the user performs a gesture on the touchpad, multiple touch events are generated that should be transformed into particular format of network message and sent to the server (running on a PC). The problem is, that they shouldn't be sent by UI thread (as GUI might freeze if the network traffic is large), but a background thread. Also, the order of messages must remain the same as the order of their generation. Normal approach would be to make the UI thread put them into some kind of a blocking queue (like for instance BlockingArrayQueue in Java) and then the background thread would read them from the queue and send to the server one by one. Unfortunately in Windows Phone you do not have access to blocking queues, you don't have access to semaphores either (therefore it is not easy to create a blocking queue). You can get semaphores by implementing Bakery Algorithm, but then again, it's not very efficient and drains the battery.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,568

    Re: How do I solve producer-consumer case in a blocking way in Windows Phone?

    Which network API do you use? If you have a stream connection and use the XyAsync methods, I think you are pretty much done. Async avoids blocking and stream connection preserves the order.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: How do I solve producer-consumer case in a blocking way in Windows Phone?

    There are some synchronization primitives available in Windows Phone 7.

    There's the Interlocked class and others in the System.Threaing namespace.

    There are a few more in the pre-release of Microsoft.Bcl.Async. With this package, you can also use the new async/await constructs of the C# 5.0 compiler.

Similar Threads

  1. Blocking SMS / Incoming Calls on a phone
    By giaviv in forum Mobile Java General
    Replies: 2
    Last Post: 2010-02-13, 09:47
  2. Push Registry - Phone restart case
    By mamatha_j2me in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2008-12-23, 05:14
  3. Phone client dial api and aiw dial data consumer api compability
    By lss0986 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2008-12-10, 09:34
  4. Phone not Connected.... how to solve?
    By Matzju in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2008-09-11, 14:50
  5. Replies: 1
    Last Post: 2002-07-16, 06:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •