You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- Thanks for your quick reply and fixing my code. Omitting mutex.WaitOne() only happened when shortening my production code for the test sample. With this fix my test no longer produces the exception mentioned.Peter Meinl– Peter Meinl2016-03-07 14:09:55 +00:00Commented Mar 7, 2016 at 14:09
- Now I can no longer reproduce the exception. Simply using the mutex without any additional measures seems to work fine. I saw you posted a similar question Named Mutex with await and settled for a solution based on a custom TaskScheduler. I am no longer shure a problem synchronizing async file IO with a named mutex exists. What do you think?Peter Meinl– Peter Meinl2016-03-07 14:31:43 +00:00Commented Mar 7, 2016 at 14:31
- @PeterMeinl In UWP direct thread managing is not possible, therefore I'm not sure now, how the solution with custom TaskScheduler would look like. Though, as I think, the LongRunning task should work - it dedicates single thread for a task and after returning from await it should be possible to safely release mutex. If your async operation is not long you may also consider synchronous waiting instead of awaiting after acquiring mutex. The best would be just to test it - maybe create a sample BTask, open a file and to the same in main UI (both with global mutex).Romasz– Romasz2016-03-07 16:51:58 +00:00Commented Mar 7, 2016 at 16:51
- My current App does synchronizes the UI with a BackTask using a named mutex and seems to work fine. As a precaution it traces mutex .WaitOne(_preventHangingTimespan) timeouts and .ReleaseMutex exceptions and reports them via ApplicationInsights. But Stephen Cleary writes in WP8 Mutex - Resource Locking "You can't use thread-affine locks with async code" and this makes me wonder if I missed something.Peter Meinl– Peter Meinl2016-03-07 18:03:36 +00:00Commented Mar 7, 2016 at 18:03
- @PeterMeinl The best would be to ask Stephen Cleary :) - maybe you can ensure if you can combine LongRunning task with mutex and awiat. IMO you can mix await and mutex, but you have to ensure that the same thread acquires and releases the mutex.Romasz– Romasz2016-03-07 18:55:36 +00:00Commented Mar 7, 2016 at 18:55
| Show 2 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you