0
Windows 8 앱의 웹 서버에서 동적 이미지를 가져 오는 다음 코드가 있습니다.CreateFileAsync UnauthorizedAccessException
private async Task httpFetcher()
{
HttpClient httpClient = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(
HttpMethod.Get, "http://www.reignofcomputer.com/imgdump/sample.png");
HttpResponseMessage response = await httpClient.SendAsync(request,
HttpCompletionOption.ResponseHeadersRead);
Uri imageUri;
BitmapImage image = null;
var imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"sample.png", CreationCollisionOption.ReplaceExisting);
var fs = await imageFile.OpenAsync(FileAccessMode.ReadWrite);
DataWriter writer = new DataWriter(fs.GetOutputStreamAt(0));
writer.WriteBytes(await response.Content.ReadAsByteArrayAsync());
await writer.StoreAsync();
writer.DetachStream();
await fs.FlushAsync();
writer.Dispose();
if (Uri.TryCreate(imageFile.Path, UriKind.RelativeOrAbsolute, out imageUri))
{
image = new BitmapImage(imageUri);
}
image1.Source = image;
}
이 대부분의 시간을 작동하지만, 어떤 이유로 내가
UnauthorizedAccessException (0x80070005입니다 E_ACCESSDENIED)을 얻을 시간이있다, HRESULT -2147024891.
오류가 임의적이며 일반적으로 작동하기 때문에 문제가있는 곳을 잘 모릅니다.
도움을 주시면 감사하겠습니다.
아마도 같은 이름의 파일이 이미 존재합니다. 'CreateFileAsync'는 기존 파일을 대체하려고하지만 다른 프로세스에 의해 잠겨 있습니다. – Leri
흠, 어떤 생각을 어떻게 확인할 수 있습니까? 그렇다면 계속하기 전에 파일 잠금이 해제 될 때까지 앱을 대기 상태로 만들 수 있습니까? – ReignOfComputer
내 의견에 직접 설명 된 상황을 만들 수 있습니다. '계속하기 전에 파일 잠금이 풀릴 때까지 앱을 어떻게 기다릴 수 있을까요? '좋은 생각은 아닙니다. 다른 프로세스가 무엇을하는지 절대 알지 못합니다. 이 프로세스가 _unlock_ file하는 데 몇 시간이 걸릴 수 있습니다. – Leri