async-await

Get stack trace of C# async calls using the API that the visual studio debugger uses

痴心易碎 提交于 2020-01-14 03:28:31
问题 Is it possible to get an equivalent stack trace that is provided by the visual studio 2019 debugger. Eg if I breakpoint in my async code inside of visual studio I see the following stack trace within the "Call Stack" window company.Common.dll!company.Common.Api.ResourcesDatabase.Lock() Line 58 C# company.Common.dll!company.Common.Api.ResourcesDatabase.ResourcesDatabase(bool openAndCreateDB) Line 29 C# company.Api.dll!company.Api.GlobalsDownloader.DownloadNewGlobals_UnderLock(System.Func

Use LINQ (Skip and Take) methods with HttpClient.GetAsync method for improving performance?

可紊 提交于 2020-01-14 03:14:09
问题 I have used the following code to retrieve the content of a JSON feed and as you see I have used the paging techniques and Skip and Take methods like this: [HttpGet("[action]")] public async Task<myPaginatedReturnedData> MyMethod(int page) { int perPage = 10; int start = (page - 1) * perPage; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri("externalAPI"); MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); client

Cancelling window closing with a task. How can I detect if task returned synchronously?

戏子无情 提交于 2020-01-14 02:55:11
问题 I am following a fairly common pattern for confirming/canceling my main window closing with an async dialog method. However, in the async task that I call to present the dialog, there are conditions where I return a boolean value immediately instead awaiting the return of a dialog task method. In those cases an exception is thrown: System.InvalidOperationException: 'Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing.

MessageDialog - needs to wait for user input

☆樱花仙子☆ 提交于 2020-01-13 19:11:30
问题 I have a ViewModel which instantiates an event in a synchronous method. The event signals to the UI that we need a "Yes" or "No" answer from the user before continuing. I am trying to display a MessageDialog and wait until the user provides an answer - Yes or No. I am having a difficult time doing this. I currently get an UnauthorizedAccessException when trying to do this. Here's a look at the code in the UI: async Task<bool> Instance_SwitchConfirmation(string question) { MessageDialog md =

Async/Await: Unexpected behaviour of ConfigureAwait

无人久伴 提交于 2020-01-13 12:13:07
问题 If you execute the following code in ASP.NET MVC, you can see in Debugging Window that it will correctly restore the thread's culture after await , even if ManagedThreadId changes: public async Task<ActionResult> Index() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread.CurrentThread.CurrentUICulture); await SomeMethod(); Debug.WriteLine(Thread.CurrentThread.ManagedThreadId); Debug.WriteLine(Thread

Vue JS waiting for data before rendering

微笑、不失礼 提交于 2020-01-13 11:28:27
问题 I'm stack since a few weeks in a problem with rendering data with VueJS. What I'm doing is making some axios calls (one inside another). My problem is that the data is rendered before the calls has completed, so the view is not showing anything. I saw some codes that do some "await" and "Async calls" but nothing seems to solve my problem. Also there is something similar here Get component to wait for asynchronous data before rendering But isn't working either here is my code: <template> <div

Understanding async - can I await a synchronous method?

扶醉桌前 提交于 2020-01-13 10:46:06
问题 Trying to understand async-await in C#, and a bit stuck in a "chicken and egg" problem, maybe. Does an async method need to call another async for it to be asynchronous? As a high level example, I'm trying to do a simple write to the file system, but not sure how I can make this task awaitable, if at all. public Task<FileActionStatus> SaveAsync(path, data) { // Do some stuff, then... File.WriteAllBytes(path, data); // <-- Allow this to yield control? // ... then return result } That line of

Inside a loop,does each async call get chained to the returned task using task's continuewith?

牧云@^-^@ 提交于 2020-01-13 10:05:13
问题 The best practice is to collect all the async calls in a collection inside the loop and do Task.WhenAll() . Yet, want to understand what happens when an await is encountered inside the loop, what would the returned Task contain? what about further async calls? Will it create new tasks and add them to the already returned Task sequentially? As per the code below private void CallLoopAsync() { var loopReturnedTask = LoopAsync(); } private async Task LoopAsync() { int count = 0; while(count < 5)

How to stop HttpClient.GetAsync(uri) from hanging? [duplicate]

冷暖自知 提交于 2020-01-13 09:58:10
问题 This question already has answers here : C# asynchronous method - help needed (3 answers) Closed 5 years ago . I have the following code that I'm using to call a uri: var uri = string.Format("Helpers/ProfileList/Online/?locationId=0&skip=0&take={0}", numProfiles); HttpResponseMessage response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); The uri is pointing at a custom web api uri (which I can debug and follow through). However, when the last return statement in the api

CPU underutilized. Due to blocking I/O?

江枫思渺然 提交于 2020-01-13 07:54:23
问题 I am trying to find where lies the bottleneck of a C# server application which underutilize CPU. I think this may be due to poor disk I/O performance and has nothing to do with the application itself but I am having trouble making a fact out of this supposition. The application reads messages from a local MSMQ queue, does some processing on each messages and after processing the messages, sends out response messages to another local MSMQ queue. I am using an async loop to read messages from