Reputation: 271
I am using a background agent (SchedulerTaskAgent) that updates some keys in my app's IsolatedStorageSettings. Everything good up to here.
When my app launches, it first removes the bgagent.
There is one case where my main app launches while the bgagent is running, so when my main app removes the bgagent and then tries to get a handle for IsolatedStorageSettings. There are 3 scenarios after this: i) handle is returned and everything is ok ii) handle is returned but no key-values exist in it, it's like nothing is there (but there are data) iii) exception because it is still used by another thread
I can deal with options 1 and 3, but not with the 2nd one. Anyone knows why this happens? When I call .Remove for my agent, i guess it needs some time to cancel it and remove it.
How can I ensure that my app starts its job after the bgagent was stopped and resources completely released?
Thanx
Upvotes: 1
Views: 844
Reputation: 271
Thanx Matt that's one approach,but i've found the best approach here http://forums.create.msdn.com/forums/p/86455/519826.aspx which suggests using a named Mutex.
Upvotes: 0
Reputation: 65566
You can't.
I've heard it recommended that you shouldn't write to IsolatedStorageSettings from backgroundAgents for just this reason.
If you really must communicate to your app from the background agent then I'd recommend writing to a separate file in IsolatedStorage that the app only ever reads from. Be sure to lock the file while reading and writing appropriately also.
Upvotes: 1