English 中文(简体)
Touch-manipulation is freezing my udp-sending in Windows Phone 7.1 (Mango)
原标题:

I have a weird problem with the Windows Phone 7.1 API. Im trying to write an app to send touch-delta from the touch-screen to move a mouse-pointer on a desktop-pc. Im using UDP-sockets but I have some performance-issues.

The sending of udp-messages seem to freeze for 0.5-1.0 sec every ~0.5 seconds or so. Im not sending huge amounts of data and Im throttling it as well. My latest attempt to find whats causing it turned out a bit unexpected.

When having a separate thread with a while-loop that keeps sending random-data everything works smooth and fine. But when I start touching the screen of the WP7-mobile I start getting these weird hiccups. I have removed all listeners on touch-events for debugging purposes and Im not doing anything else in my app then sending this data on a UDP-socket. But why is it freezing up like this when I move my finger over the screen? It kind of makes it impossible to write an app like this.

I ve heard that touch-manipulation should be moved to a dedicated thread, is that included in the Beta2 refresh of WP7.1?

The code goes somewhat like this:

    new Thread(() =>
    {
        while (true)
        {
            _event.Reset();
            _socket.SendToAsync(_args);
            _event.WaitOne();
            Thread.Sleep(5);
        }
    }).Start();

The event-handle is set when SendToAsync is completed. So it keeps sending udp-data about every 5 ms. It works fine (I can receive in a steady and rapid rate) as long as I dont touch and drag my finger on the phone s screen. Then I start getting 1 sec freezings in regular intervals. Very strange since Im running the udp-firing on a separate thread. Is the CPU of the phone being overloaded in some way when its processing manipulation? Could that be causing the hiccups?


Update

I ve refrased and updated this question in another thread to make it a bit more clear:

Poor UDP performance with Windows Phone 7.1 (Mango)

问题回答

Everything runs on the UI thread till you push it to another thread. Most of my event handlers look like this

ThreadPool.QueueUserWorkItem(state => /* do stuff */);

I have Mango b2 and it is true that some stuff has been moved off the UI thread but this is erratic and it s easy to do it yourself.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签