winrt-async

Async Implementation of IValueConverter

白昼怎懂夜的黑 提交于 2019-11-26 20:13:54
If an async Method which I want to trigger inside a IValueConverter. Is there a better Wait then forcing it to be synchronous by calling the result Property? public async Task<object> Convert(object value, Type targetType, object parameter, string language) { StorageFile file = value as StorageFile; if (file != null) { var image = ImageEx.ImageFromFile(file).Result; return image; } else { throw new InvalidOperationException("invalid parameter"); } } You probably don't want to call Task.Result , for a couple of reasons. Firstly, as I explain in detail on my blog, you can deadlock unless your

Async Implementation of IValueConverter

烂漫一生 提交于 2019-11-26 07:29:39
问题 If an async Method which I want to trigger inside a IValueConverter. Is there a better Wait then forcing it to be synchronous by calling the result Property? public async Task<object> Convert(object value, Type targetType, object parameter, string language) { StorageFile file = value as StorageFile; if (file != null) { var image = ImageEx.ImageFromFile(file).Result; return image; } else { throw new InvalidOperationException(\"invalid parameter\"); } } 回答1: You probably don't want to call Task