async-await

Await async clarification

拟墨画扇 提交于 2019-12-24 12:21:23
问题 I am trying to learn/understand more about async/await in C# and I would put myself in rookie category so all your comments/suggestions are welcome. I wrote small test to have better understanding and clarification about await/async. My program freezes after "GetStringLength" call I tried reading several things but looks like I am stuck and I thought of taking expert opinion on what I might be doing wrong. Can you please guide me or point me in right direction here? using System; using System

When exactly do Page.RegisterAsyncTask's get called?

最后都变了- 提交于 2019-12-24 12:18:43
问题 I am running into confusing behavior related to async code registered on an ASP.NET page with RegisterAsyncTask, ViewState, and checkboxes, and I need to know exactly when these async-tasks run relative to when ViewState is saved. I have a few checkboxes inside an ASP:PlaceHolder control. I am reading a record and populating the checkboxes, then I make the PlaceHolder visible. If all this is synchronous - maybe within Page_Load - all is well. If this is registered as an async task the

async library calls relying on each other and how to handle?

孤街醉人 提交于 2019-12-24 11:33:44
问题 this is a follow on from a previous question I posted Calling an async method using a Task.Run seems wrong? I thought the code written by the contractor was wrong but following on from the answers provided I'm now wondering if it's the libraries fault. This library exposes two methods that I need to use. One returns a "template" and one consumes part of this template (it does in my implementation anyway). But both are async methods returning Tasks . To explain my library has methods: public

nodejs retry function if failed X times

北城余情 提交于 2019-12-24 11:27:44
问题 I want my function to execute X(=3) times until success. In my situation I'm running kinesis.putRecord (from AWS API), and if it fails - I want to run it again until it succeeds, but not more than 3 tries. I'm new to NodeJS, and the code I wrote smells bad. const putRecordsPromise = function(params){ return new Promise((resolve, reject) => { kinesis.putRecord(params, function (err, data) { resolve(err) }); }) } async function waterfall(params){ try{ let triesCounter = 0; while(triesCounter <

How to wait for multiple asynchronous calls from for loop?

落花浮王杯 提交于 2019-12-24 11:03:37
问题 Code without any handling: for (i=0; i<dbImgCount; i++){ (function(i) { imgDownload(FolderPath[i].FolderPath, function (next){ var url = FolderPath[i].FolderPath; const img2 = cv.imread(imgDownload.Filename); match({url, img1, img2, detector: new cv.ORBDetector(), matchFunc: cv.matchBruteForceHamming, }); }) })(i); } In the above code, imgDownload is an async function which will download image, match will match features of downloaded image with another image. Need to execute a function after

Use Async with .then promise

空扰寡人 提交于 2019-12-24 10:58:03
问题 Hello after setup a simple async function with promise return i'd like to use then promise instead of try! But is returning await is a reserved word for the second await in the function. i've tried to place async return promise the data! but did not worked either async infiniteNotification(page = 1) { let page = this.state.page; console.log("^^^^^", page); let auth_token = await AsyncStorage.getItem(AUTH_TOKEN); fetch(`/notifications?page=${page}`, { method: "GET", headers: { Accept:

using async await on Windows Phone 7

寵の児 提交于 2019-12-24 10:57:23
问题 Write the code which asynchronus load BitmapImage. public async void AsyncLoadPhotoNotesFromIsolatedStorage() { IsolatedStorageSettings appStorageSettings = IsolatedStorageSettings.ApplicationSettings; if (appStorageSettings.Count > 0) { var loadedPhotoNotes = new ObservableCollection<PhotoNote>(); foreach (Object obj in appStorageSettings.Values) { var tempPhotoNote = (PhotoNote) obj; BitmapImage bitmapImage = null; Stream imageStream = await LoadImageAsync(tempPhotoNote.Id); if (imageStream

Exception not caught in Task.Run wrapped method

痴心易碎 提交于 2019-12-24 10:48:06
问题 New to async await integration in C# 5. I'm working with some basic Task based methods to explore async await and the TPL. In this example below I'm calling a web service with a timeout of 5 seconds. If the timeout expires it should throw an exception so I can return false from the method. However, the timeout never occurs, or maybe it does but the Task never returns. public static Task<bool> IsConnectedAsync() { return Task.Run(() => { try { using (WSAppService.AppService svc = new

How to cancel custom awaitable

为君一笑 提交于 2019-12-24 10:44:45
问题 I've read Stephen Toub's blog about making a custom awaitable for SocketAsyncEventArgs. This works all fine. But what I need is a cancellable awaitable and the blog doesn't cover this topic. Also Stephen Cleary unfortunately doesn't cover in his book how to cancel async methods that don't support cancellation. I tried to implement it myself, but I fail with the TaskCompletionSource and Task.WhenAny because with the awaitable I'm not actually awaiting a task. This is what I would like to have:

use Task.Run() inside of Select LINQ method

江枫思渺然 提交于 2019-12-24 10:39:52
问题 Suppose I have the following code (just for learninig purposes): static async Task Main(string[] args) { var results = new ConcurrentDictionary<string, int>(); var tasks = Enumerable.Range(0, 100).Select(async index => { var res = await DoAsyncJob(index); results.TryAdd(index.ToString(), res); }); await Task.WhenAll(tasks); Console.WriteLine($"Items in dictionary {results.Count}"); } static async Task<int> DoAsyncJob(int i) { // simulate some I/O bound operation await Task.Delay(100); return