Open soroshsabz opened 8 years ago
This appears to be a bug with the behavior of the method AwaitExtensions.SwitchOffMainThreadAsync
.
The workaround (at least that I've found) is to spawn a new thread using ThreadPool
or the Thread
class to call the PCLStorage APIs. You can use a TaskCompletionSource
to asynchronously await the results of the new thread's task.
I am also experiencing this bug
Can you fix this? I'm using a PCL library with profile44, I don't have Thread
class, and importing ThreadPool
requires Windows.Foundation.UniversalApiContract
and Windows.Foundation.FoundationContract
that gives problems to me.
Also running on an other thread doesn't work for me. I've tried to implement this into the UWP solution, and inject it into the PCL library where I'm using PCLStorage. It still freeze on await Task.Delay(10)
.
class AsyncRunner : IAsyncRunner
{
public async Task RunOnOtherThread(Action action)
{
var asyncAction = ThreadPool.RunAsync(_ => action());
while (asyncAction.Status != Windows.Foundation.AsyncStatus.Completed)
await Task.Delay(10);
}
}
Maybe this helpful for you, try some function like below
public static async Task<ExistenceCheckResult> CheckExists(this IFolder rootFolder, string fileName)
{
return await Task.Run(() => rootFolder.CheckExistsAsync(fileName)).ConfigureAwait(false);
}
and call it synchronous with get Result to resolve your problem temporary.
Thank you, it works but only sometimes. It still can freeze, on CheckExists and on other calls. We really need a fix...
Yes, you right. I need to fix it, but when I call all asynchronous function with top pattern, I could not see freeze any more. Did you sure call all API with top pattern?
I've upgrade every single call to the library with your pattern, and it seems to work now. Before I had OpenAsync on IFile to update, and it froze on alternate moments. Thank you! Are you a maintainer?
You are welcome :) No, I am not maintainer. Unfortunately, I do not know why this library is not maintained continuously.
I think the error is here:
public async Task<ExistenceCheckResult> CheckExistsAsync(string name, CancellationToken cancellationToken) {
var result = await _wrappedFolder.GetItemAsync(name).AsTaskNoThrow(cancellationToken);
ConfigureAwait(false) is missing
From the comments this seems like a 1 line change, but as the last check in was Jan 2015. I'm not holding my breath. Frustrating
nuget update?
+1 Getting this fix in the nuget package would be most helpful: still repros on 1.0.2. Not surprising since it was published 1/18/2015. Can someone make another build, so we can get the fixed library via nuget? Help with this would be most appreciated!
fixed this in the source ages ago. Still no nuget update!
2019, getting this problem with the Nuget package too. Can we update this package?
@Tamachan87 Ditch this nuget entirely and swap it all for File
and Directory
which have now been implemented for .Net standard 2.0
ITNOA
Hi,
When I try to check exists file such as below code
My platform:
My process freeze, I found one problem similar to me from here.