Answered by:
Synchronization to a shared resource, e.g. a file, between background task and app

Question
-
What would be a good way of doing this?Thursday, July 3, 2014 11:15 AM
Answers
-
for Semaphore you can better use SemaphoreSlim http://msdn.microsoft.com/en-us/library/system.threading.semaphoreslim(v=vs.110).aspx
but this one shouldn't be Inter-process. so mutex should be the way to go
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Marked as answer by Jamles HezModerator Tuesday, July 15, 2014 2:35 AM
Thursday, July 3, 2014 1:22 PM
All replies
-
depends on how much data, and are your shared resources in the same app package or in different packages?
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
Thursday, July 3, 2014 11:16 AM -
A few k of data, so small, and the same package.Thursday, July 3, 2014 11:20 AM
-
ApplicationData.Current.LocalSettings for just settings and ApplicationData.Current.LocalFolder for files would be the best approach
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
Thursday, July 3, 2014 12:55 PM -
Dave thanks, I should have been a little clearer in the question. - This is concerning synchronization of access, these are good examples of where the file or data is stored.
The app and the background task could attempt to read/write to the same resource at the same time. What would be a good way to manage this thread synchronization to the resource?
Thursday, July 3, 2014 1:13 PM -
a mutex should do the job for this:
http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx
for phone this worked, for windows I never tried out but seems to be supported in a store app so guess it should work here too
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Edited by Dave SmitsMVP Thursday, July 3, 2014 1:17 PM
Thursday, July 3, 2014 1:16 PM -
This is the same line as my thinking, because it is inter-process.
There is a named Semaphore.
http://msdn.microsoft.com/en-us/library/system.threading.semaphore(v=vs.110).aspx
Both could, in theory be right.
Ta.
- Edited by Ben - GGT Thursday, July 3, 2014 1:37 PM
Thursday, July 3, 2014 1:20 PM -
for Semaphore you can better use SemaphoreSlim http://msdn.microsoft.com/en-us/library/system.threading.semaphoreslim(v=vs.110).aspx
but this one shouldn't be Inter-process. so mutex should be the way to go
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Marked as answer by Jamles HezModerator Tuesday, July 15, 2014 2:35 AM
Thursday, July 3, 2014 1:22 PM