Reputation: 229
How I can use FileIO.ReadTextAsync in windows universal apps so that it will be thread safe? Because trying something similar like
lock(lockObject)
{
var data = await ReadTextAsync(fileName);
}
but using await
in lock
is not supported =(.
Upvotes: 1
Views: 140
Reputation: 1116
It's not supported because there are no (managed) threads during an I/O call, and the current method will be continued later, potentially on another thread.
Lock is a synchronous concept, and since you're serializing access already, can you just call ReadText
instead of ReadTextAsync
? Do you really benefit from async in your case?
Upvotes: 1