views:

1127

answers:

5

I have an application that needs to "poll" a webservice to see if the user has any new messages waiting. I have no control over the webservice so I cannot switch to a "push" mechanism, I'm stuck making a request every X number of seconds to see what's available.

I am using a System.Threading.Timer to make the request every so often, but am encountering a few problems. The biggest is that it stops running when the phone is sent into "standby" mode (screen off, but still able to get calls and email/txt notifications).

I'd really like it to behave like other background applications. What can I do to make it work without being too big of a drain on the battery?

+1  A: 

There's nothing you can do, AFAIK. Standby mode is meant to suspend the processor to save power, and there's no way your code can execute if the processor isn't running. There are things your application can do to prevent the device from going into standby mode, but this really isn't advisable at all.

MusiGenesis
Then how does ActiveSync do it? How do I still get emails when I've turned it off and put it in my pocket?
Jake Stevenson
All good questions. I think actually the processor isn't completely shut down in standby, and can be turned back on remotely by ActiveSync or the cellphone or the wireless "card". Just not by your code, since it isn't running in standby mode.
MusiGenesis
+1  A: 

Yep. Similar to how MusiGenesis has answered, you won't be able to do much without keeping the device up and running. Similar to how some phones will notify that "Game/App Running" and thus your battery is being slapped around.

What about writing an interface from your phone to leverage text messaging (which still works) and get it to send a text message to the web service? Would that be possible? I'm guessing that sort of method might also stop running, but I figure it's a thought?

Mat Nadrofsky
+1  A: 

I'm not sure about compact framework, but in Win32 there is WaitableTimer that can wake up computer from standby. It takes some native calls though as there's no wrapper in .Net.

Stanislav Kniazev
PInvoke is pretty easy. This is a good idea.
MusiGenesis
I'm going to try this and see if it works.
MusiGenesis
There is no WaitableTimer in CE
ctacke
A: 

Although you can't modify the webservice, you might be able to add a second "shadow" webservice in between your clients and the original webservice. The shadow webservice could poll the original webservice and then "push" anything it finds out to the PDAs.

I think you might still have the same problem, though. I've never done "push" from a webservice, but I think it's basically implemented by having the client make an initial call to a webservice method that takes a delegate to a method in the client, which the webservice then hangs onto. When the webservice needs to push something, it calls that delegate. If the client has gone into standby mode in the meantime, the attempt to call the delegate from the server will fail.

MusiGenesis
+3  A: 

Hate to answer my own question, but I was pointed to this, which was able to perform even when the device is asleep. Looks like it's working perfectly.

Jake Stevenson
Answering your own question is a good thing. And the solution you found is a very good one (though I may be biased).
ctacke
Came across this on a Google search, and the link to LIT was just what I needed, thanks!
rally25rs

related questions