views:

200

answers:

3

Hello,

I have a windows mobile 5.0 application (smartphone) that contains a flat data file (CSV), which contains a header row (two doubles), and a list of entries (two doubles, DateTime, and a string).

Occasionally, I need to "sync" the mobile application with a desktop application. The desktop application should read the CSV from the mobile device, and replace it with a new CSV file, based on the contents of the old one.

This seems pretty easy via RAPI (I'm guessing), but I need to ensure that the mobile application is not running. Is there a way to do this?

Mutex? Remote Process Viewer like stuff? File locking?

Thanks for any help you have

Mike

A: 

Just thought of an easy way.

Every 3 seconds the program is running, update a registry key with the current datetime.

When I want to sync, check the mobile registry, check it again 5 seconds later. If the values changed, the program is still running.

Mike Christiansen
This would be a really bad idea. Having the mobile application perform a task with such frequency would affect it's ability to go into low power mode. This would greatly impact battery life.
Matt Lacey
Yeah, didn't think of that.
Mike Christiansen
+1  A: 

For whatever reason, the built-in RAPI Functions don't have anything for checking running processes like the ToolHelp API's. With C you could create a set of custom functions in a device library that call the ToolHelp APIs and in turn are called through CeRapiInvoke (which is a generic catch-all entry point for custom RAPI functions). Unfortunately there's no simple mechanism to do this in managed code.

ctacke
+1  A: 

Just use a simple file locking mechanism for the file being read/updated.

Either rename the file before use or create a second 'lock' file which you can check for the existence of.

Matt Lacey
And if the app crashes and doesn't delete the file?
ctacke
Yes, have a time limit for lock files. If the lock is 2 minutes old, but no app should ever hold a lock for more than a minute, ignore the lock.
Matt Lacey
Sounds kludgey. A simple RAPI function would do it right.
ctacke