async-await

Does WebClient.DownloadFileTaskAsync() never actually timeout?

三世轮回 提交于 2021-02-09 15:55:33
问题 In the pre-async days, people wanted to know how to set the timeout on WebClient and the answer was simply to extend the base class and override GetWebRequest() and set the timeout there. protected override WebRequest GetWebRequest(Uri address) { // NOTE: this override has no affect if the Async methods are used!!! WebRequest request = base.GetWebRequest(address); ((HttpWebRequest)request).Timeout = 20 * 60 * 1000; ((HttpWebRequest)request).ReadWriteTimeout = 20 * 60 * 1000; return request; }

Task.ContinueWith fires before task is finished

浪尽此生 提交于 2021-02-08 21:49:12
问题 I'm trying to start a task after I register a continuation for it. But continuation fires immediately after await Task.Delay() is called. using System; using System.Linq; using System.Threading.Tasks; namespace ConsoleApplication30 { class Program { static void Main(string[] args) { var task = new Task(async delegate { Console.WriteLine("Before delay"); await Task.Delay(1000); Console.WriteLine("After delay"); }); task.ContinueWith(t => { Console.WriteLine("ContinueWith"); }); task.Start();

Cannot implicitly convert type IAsyncOperation<StorageFile> to StorageFile

做~自己de王妃 提交于 2021-02-08 19:45:59
问题 What the hell is wrong with my code? private void BrowseButton_Click(object sender, RoutedEventArgs e) { FileOpenPicker FilePicker = new FileOpenPicker(); FilePicker.FileTypeFilter.Add(".exe"); FilePicker.ViewMode = PickerViewMode.List; FilePicker.SuggestedStartLocation = PickerLocationId.Desktop; // IF I PUT AWAIT HERE V I GET ANOTHER ERROR¹ StorageFile file = FilePicker.PickSingleFileAsync(); if (file != null) { AppPath.Text = file.Name; } else { AppPath.Text = ""; } } It gives me this

async/await __generator is not defined

旧街凉风 提交于 2021-02-08 15:16:44
问题 I am trying to use async/await functions with angular2-webpack-starer and typescript (which now have support for this functions targeting es5), but I'm getting error: This is code inside component: // function inside component async checkSlug(slug: string) { // nothing here } I am using webpack2.2 and typescript 2.1.5. This is my tsconfig: { "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true,

“await this.method();” doesn’t work in static method

拜拜、爱过 提交于 2021-02-08 13:45:24
问题 I know of the ES6 await feature and I’d like to use it in a function I created in a class. It works well, but when the function is a static function, it doesn’t. Is there any reason for that? Also, what will be the right way to be able to use await inside a static function? class MyClass { resolveAfter2Seconds() { return new Promise(resolve => { setTimeout(() => { resolve('resolved'); }, 2000); }); } static async asyncCall() { console.log('calling'); var result = await this

How would you call async method in a method which cannot be async in C# without using .Result

你。 提交于 2021-02-08 12:55:07
问题 I am overriding a method, HandleRequirementAsync, so I can't modify the return type of that method. However, I am calling a method in UserManager which is async and requires an await so I had to put this code in another method. protected override Task HandleRequirementAsync( AuthorizationHandlerContext context, EducationArmRequirement requirement) { if (!IsEducationGroup(context).Result) { return Task.FromResult(0); } context.Succeed(requirement); return Task.FromResult(0); } protected async

How to update UI immediately when running an async task

亡梦爱人 提交于 2021-02-08 09:58:13
问题 I have an Asp.Net 4.5 webforms application with a report which I'm trying to run using async await. Here is an example of the code I'm using: protected async void btnReport_Click(object sender, EventArgs e) { lblStatus.Text = "Working!"; await LongRunningTask(); } private async Task LongRunningTask() { await Task.Delay(5000); lblStatus.Text = "Done!"; } Everything I've read seems to suggest that the first method should complete immediately and update the label but this is not the case. The

How to update UI immediately when running an async task

。_饼干妹妹 提交于 2021-02-08 09:57:52
问题 I have an Asp.Net 4.5 webforms application with a report which I'm trying to run using async await. Here is an example of the code I'm using: protected async void btnReport_Click(object sender, EventArgs e) { lblStatus.Text = "Working!"; await LongRunningTask(); } private async Task LongRunningTask() { await Task.Delay(5000); lblStatus.Text = "Done!"; } Everything I've read seems to suggest that the first method should complete immediately and update the label but this is not the case. The

Await nothing? Using an empty await to break up a large synchronous function

陌路散爱 提交于 2021-02-08 08:52:31
问题 I have a rather simple question that I can't find an answer to. I have an async function called foo that never awaits, so it's run synchronously. In foo is a long-running loop and it pushes a lot of data into a intermediary buffer. There is an async operation using RxJS that will pull and process data from that buffer, but it won't execute until my long running loop yields somehow, or when the loop is completely done pushing millions of data points into the intermediary buffer (not good). Can

Make my asyncForEach() Parallel Instead of Sequential

六眼飞鱼酱① 提交于 2021-02-08 08:27:45
问题 So I want the code inside loop to run simultaneously but the code after the loop to run only when loop is done processing: Code async function asyncForEach(array, callback) { for (let index = 0; index < array.length; index++) { await callback(array[index], index, array); } } const waitFor = (ms, num) => new Promise(r => setTimeout(() => { console.log(num) r() }, ms)); const doStuff = async() => { await asyncForEach([1, 2, 3], async(num) => { await waitFor(1000, num); }) console.log('Done'); }