async-await

Async property in c#

眉间皱痕 提交于 2019-12-29 07:05:49
问题 In my windows 8 application there is a global class where there are a few static properties like: public class EnvironmentEx { public static User CurrentUser { get; set; } //and some other static properties //notice this one public static StorageFolder AppRootFolder { get { return KnownFolders.DocumentsLibrary .CreateFolderAsync("theApp", CreationCollisionOption.OpenIfExists) .GetResults(); } } } You can see I want to use the application root folder somewhere else in the project, so I make it

How to load image src url in vuejs asyncronously?

被刻印的时光 ゝ 提交于 2019-12-29 07:00:53
问题 The image url is printing in console but not rendering to src attribute. How to achieve this with async and await in vuejs? <div v-for="(data, key) in imgURL" :key="key"> <img :src= "getLink(data)" /> </div> Where imgURL contains file name and it is collections of file names. methods: { async getLink(url){ let response = await PostsService.downloadURL({ imgURL : url }) console.log(response.data) return response.data } } I am getting URL from the backend with axios. 回答1: That's not possible

How to copy HttpContent async and cancelable?

走远了吗. 提交于 2019-12-29 06:49:14
问题 I'm using HttpClient.PostAsync() and the response is an HttpResponseMessage . Its Content property is of type HttpContent which has a CopyToAsync() method. Unfortunately, this is not cancelable. Is there a way to get the response copied into a Stream and pass a CancellationToken ? I am not stuck with CopyToAsync() ! If there is a workaround, that would be fine. Like read a couple of bytes, check if canceled, continue reading and so on. The HttpContent.CreateContentReadStreamAsync() methods

Throw Exception inside a Task - “await” vs Wait()

℡╲_俬逩灬. 提交于 2019-12-29 06:41:11
问题 static async void Main(string[] args) { Task t = new Task(() => { throw new Exception(); }); try { t.Start(); t.Wait(); } catch (AggregateException e) { // When waiting on the task, an AggregateException is thrown. } try { t.Start(); await t; } catch (Exception e) { // When awating on the task, the exception itself is thrown. // in this case a regular Exception. } } In TPL, When throwing an exception inside a Task, it's wrapped with an AggregateException. But the same is not happening when

Throw Exception inside a Task - “await” vs Wait()

南楼画角 提交于 2019-12-29 06:41:02
问题 static async void Main(string[] args) { Task t = new Task(() => { throw new Exception(); }); try { t.Start(); t.Wait(); } catch (AggregateException e) { // When waiting on the task, an AggregateException is thrown. } try { t.Start(); await t; } catch (Exception e) { // When awating on the task, the exception itself is thrown. // in this case a regular Exception. } } In TPL, When throwing an exception inside a Task, it's wrapped with an AggregateException. But the same is not happening when

Async and Await with HttpWebRequest.GetResponseAsync

只谈情不闲聊 提交于 2019-12-29 06:40:23
问题 I am trying to use Async and Await when making a web request and am finding that it never gets past the await line. I am doing this from a Metro app, but I also verified the problem in a winforms app. public async Task<string> DoSomething() { string url = "http://imgur.com/gallery/VcBfl.json"; HttpWebRequest request = HttpWebRequest.CreateHttp(url); var ws = await request.GetResponseAsync(); return ws.ResponseUri.ToString(); ; } If I don't use await and instead perform a synchronous wait, it

Async and Await with HttpWebRequest.GetResponseAsync

删除回忆录丶 提交于 2019-12-29 06:40:11
问题 I am trying to use Async and Await when making a web request and am finding that it never gets past the await line. I am doing this from a Metro app, but I also verified the problem in a winforms app. public async Task<string> DoSomething() { string url = "http://imgur.com/gallery/VcBfl.json"; HttpWebRequest request = HttpWebRequest.CreateHttp(url); var ws = await request.GetResponseAsync(); return ws.ResponseUri.ToString(); ; } If I don't use await and instead perform a synchronous wait, it

Future/async/await in Dart

断了今生、忘了曾经 提交于 2019-12-29 05:46:05
问题 I have a function loadData that loads some text from a file: Future<String> loadAsset() async { return await rootBundle.loadString('assets/data/entities.json'); } The loadString method is from Flutter SDK, and is asynchronous. The loadAsset method is then called in another method, that must me marked as async , since loadAsset is async and I need to use await : Future<List<Entity>> loadEntities() async { String jsonData = await loadAsset(); return parseData(jsonData); } The parseData method

Which ASP.NET lifecycle events can be async?

只谈情不闲聊 提交于 2019-12-29 03:03:47
问题 I've written a custom ASP.NET control and I just updated it to have an async Load event handler. Now I'm getting this error: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>. The page does have the <%@ Page Async="true" %> tag already. So I take it

How do I convert this to an async task?

蹲街弑〆低调 提交于 2019-12-28 20:41:44
问题 Given the following code... static void DoSomething(int id) { Thread.Sleep(50); Console.WriteLine(@"DidSomething({0})", id); } I know I can convert this to an async task as follows... static async Task DoSomethingAsync(int id) { await Task.Delay(50); Console.WriteLine(@"DidSomethingAsync({0})", id); } And that by doing so if I am calling multiple times (Task.WhenAll) everything will be faster and more efficient than perhaps using Parallel.Foreach or even calling from within a loop. But for a