Click here to Skip to main content
15,886,565 members
Everything / Await

Await

Await

Great Reads

by David Deley
Internal working of the await keyword
by Dev Leader
Problem with async void and a solution for it
by ipavlu
The Cross-Platform Object-Oriented approach to Synchronization Primitives for .NET and .NET Core based on one shared pattern between two interfaces for General Threading and Async/Await.
by Federico Alterio
Convert an Event-based API to an awaitable pattern API

Latest Articles

by Federico Alterio
Convert an Event-based API to an awaitable pattern API
by Dev Leader
Problem with async void and a solution for it
by David Deley
Internal working of the await keyword
by Gerd Wagner
The evolution of asynchronous programming in JavaScript: callbacks, promises, async/await

All Articles

Sort by Score

Await 

15 Mar 2022 by David Deley
Internal working of the await keyword
6 Feb 2023 by Dev Leader
Problem with async void and a solution for it
24 Mar 2019 by ipavlu
The Cross-Platform Object-Oriented approach to Synchronization Primitives for .NET and .NET Core based on one shared pattern between two interfaces for General Threading and Async/Await.
30 Apr 2023 by Federico Alterio
Convert an Event-based API to an awaitable pattern API
15 Mar 2016 by RickZeeland
Here is a good article by Stephen Cleary: Async/Await - Best Practices in Asynchronous Programming[^]But I'm afraid he says what you don't want to hear:Quote:As you convert synchronous code to asynchronous code, you’ll find that it works best if asynchronous code calls and is called by...
29 Dec 2017 by ipavlu
Optionally awaitable simple to use Concurrent Priority Queue.
12 Dec 2013 by Sergey Alexandrovich Kryukov
Why?! Create a separate thread to work with each separate telnet server and work synchronously. Synchronize those threads using thread synchronization in those rare cases when it is needed.I think asynchronous APIs get popularity when threads were not a commonplace, or just because many...
19 Jan 2016 by Richard Deeming
How about something like this:public void GetDocumentWithCallback(Action callback, long ID){ Task task = GetDocumentAsync(ID); task.ContinueWith(t => callback(t.Result));}NB: Unlike the async version, callback will not be executed in the same context as...
24 Mar 2019 by ipavlu
The Cross-Platform Object-Oriented approach to Synchronization Primitives for .NET and .NET Core based on one shared pattern between two interfaces for General Threading and Async/Await.
6 Jul 2021 by Gerd Wagner
The evolution of asynchronous programming in JavaScript: callbacks, promises, async/await
15 Jul 2014 by Matthew Dennis
// assuming you have created a CancellationToken so you can cancel the Telnet Monitors.List telnetTasks = new List();for (var i = 0; i
21 Jan 2016 by Richard Deeming
Assuming you want the return values to be 1 and 2, use the Interlocked.Increment Method[^] to increment the field, and store the result in a local variable to return at the end of the method:public class MyClass{ private int count = 0; public async Task GetCount() ...
27 Nov 2016 by Dave Kreskowiak
Your code is essentially single threaded. You've got 2 threads, but one is completely blocked waiting on the other. In any case, putting the LoadData code on a background thread, since it's the only thing you're doing, is no different than if you completely skipped all the Task/async/await...
6 May 2019 by OriginalGriff
Talk to the authors: if you go to your link page, you will find a line: Support questions: Stack Overflow[^] Follow the link, and ask them.
12 Apr 2021 by Richard Deeming
You haven't understood how async and await work. The result of an async function is a Promise, which will be resolved at some later time with the actual return value. Inside another async function, you can await that Promise to get the return...
6 Feb 2023 by Richard Deeming
You need to await the task returned from GetProductTypes. Assuming you're using .NET Core / .NET 5+, you can then simply return that result - ActionResult has an implicit conversion[^] from T: [HttpGet] public async...
22 Nov 2013 by NeonMika
Hi codeproject-community!I'm just diggin' into the TAP and I'm hoping you can help me with a problem.Let me first explain what I want to achieve:I want to read from a RSS-feed every 10 seconds and want to write it's items to output it somehow on my form.My idea:I wrote an...
22 Nov 2013 by NeonMika
Okay, after reading some blogs i found some solution that work's pretty good for me: private Action getRss = null; private TaskScheduler ui = TaskScheduler.FromCurrentSynchronizationContext(); public ObservableCollection GuiListRssItems = new...
11 Dec 2013 by Member 10440446
Hi guys, any idea on how am I suppose to create an application on C# 5.0 using async await Telnet client.My scenario is that I have to telnet multiple servers at the same time. Also, i need it to check the servers continuously just like a ping /t function.Thanks much.. :)
20 Dec 2013 by Yvan Rodrigues
The UI has a "loading" spinner. During the data loading below, the UI is responsive. During the LINQ, it freezes. The computer has 8 cores. public async static Task Load() { if (_loader == null) { _loader = Task.Run(() => ...
20 Dec 2013 by bowlturner
if you have visual studio 2012 or greater (.Net Framework 4.5 I think) you can use the Async keywords http://msdn.microsoft.com/en-us/library/hh156513.aspx[^]if not your mostly likely solution will be to put the linq on it's own thread.
17 Feb 2014 by Marc Clifton
I thought one of the points about async/await is that when the task completes, the continuation is run on the same context when the await was called, which would, in my case, be the UI thread.So for example:System.Diagnostics.Debug.WriteLine("2: Thread ID: " +...
30 Apr 2014 by 123456789igor
Hello, i try to write a simple asynchronous client/server apps. I know how do it using callback, but i want to invistigate how write client+server using await/async and c# 5.0. Please, help me. It should be simple. Only connect and transfer some bytes.I know that this can be done using...
1 May 2014 by 123456789igor
now server can send to client array of byte. But client recieved only 1 iteration. How i can do, that if client connected then it always recieve information from server?Server:public ServerSocket(IPAddress ipAddress, int port) { _server = new...
30 Jun 2014 by Kyle Gottfried
I've been trying to turn the code sample at http://code.msdn.microsoft.com/office/CSVSTOViewWordInWPF-db347436[^] into an asynchronous program. I've been running into issues where running the program by calling AssignDocument(w,x) using await causes it to run synchronously instead of...
14 Oct 2014 by mahesh kumar BM
here is the below code that is used to get the list of templates from sendgrid using async and await feature. but due to some limitations i cant use these feature in my application which is in .net 3.5/4 and i use vs 2010. i just need the equivalent code which will run at background without...
28 Nov 2014 by girishkalamati
if its possible you can go on with spinning up multiple thread , to process the blob items as async process !u can use the following code , it will for sure improve the performance :async public static Task ListBlobsSegmentedInFlatListing(){ // Retrieve storage account from...
8 Dec 2014 by Santiago Fabian
Protected void Page_Load(object sender, EventArgs e){ XDocument response = ThirdPartyAPI.HttpRequest(someParams); if(response != null) { var node = response.Root.Elements("documents").Elements("document"); string url =...
8 Dec 2014 by Assil
Looks to me that ThirdPartyAPI.HttpRequest is asynchronous method, in which case there should be some method or property in ThirdPartyAPI that indicates whether the HttpRequest is still busy or done..and that very API could be used in lieu of if(response != null)Can you look into that?
19 Jan 2016 by Henrik R L
HiI need to have my own C# function in both an awaitable async version and in a version that takes a callback function as a parameter and can be called from multiple threads at the same time. The callback version must be based on the async version.My awaitable function is:public...
21 Jan 2016 by Henrik R L
HiLet's say you have a function like:public class MyClass{ //Asume that this for some reason needs to be a member variable private int count=0; public async Task GetCount() { ++count; //Could be some real work to do in a...
21 Jan 2016 by Afzaal Ahmad Zeeshan
Because as per C#, it is illegal to do so. Quote[^]:An await expression cannot be used in a synchronous function, in a query expression, in the catch or finally block of an exception handling statement, in the block of a lock statement, or in an unsafe context.The thing is, if you call...
26 Apr 2016 by Member 10312908
Hello everyone, I have a problem with UI locking.Why the UI is freezed? I think it shouldn't be until DownloadHotListAsync finish.Thanks a lot.What I have tried:private async void RetrieveHotlist(object sender, RoutedEventArgs e) //button click { await...
26 Apr 2016 by VR Karthikeyan
Check this,1. c# - A list view in WPF makes the UI frozen duing data binding - Stack Overflow[^]2. c# - Preventing wpf window from hanging - Stack Overflow[^]
26 Apr 2016 by George Swan
Could I suggest a few changes? After the await statement in the button click handler you are back on the dispatcher thread so you don’t need the Dispatcher BeginInvoke stuff. It is generally not a good idea to try to martial the threads yourself, you will get in a tangle. Leave all that to...
27 Nov 2016 by SrikantSahu
I am trying to bind a gridview using EF 6.0 raw Sql query with Async, but the system goes on for endless execution and task.Result is never populated.What I have tried:protected void Page_Load(object sender, EventArgs e) { var task = LoadDataAsync(); task.Wait();...
27 Sep 2017 by Charlie Andrews
Hello , I am trying to create an asp.net web api. This API will be called from a scheduler from cloud once every 15 minute where this API will look in db and Call an external third party web-service multiple times with different parameters.External service will just return true of false. ...
27 Sep 2017 by Richard Deeming
You're creating a series of Task objects, but never waiting for them to complete. The calling method will return before the work has finished. And if any of the tasks fails, it could end up taking down your entire process with an "unobserved exception" error. You should make the...
8 Dec 2017 by Member 13363439
Hi i have 3 method i want to load data like First come First Display.means which method execute first that should display in UI part .it should not wait for all method to be Complete. Here is My Sample code. this code is waiting for all function to be complete than page is loading.please help me...
13 Mar 2018 by Bala Manikanta Koorakula
I am new with Async and await using C# Programming. In WebAPI, we have created two API Controllers one with Async and await Programming and other is without that. We have done load testing using JMeter and we have got following results. Users Sync ...
12 Apr 2018 by rikidev
Hi guys with the code below I open a pool connection to sql server! My problem is that I should wait for the query to run, then return, how can I implement this? What I have tried: const DbConfig = require('../Config/DatabaseConfig.js'); const sql = require('mssql'); async function...
20 Aug 2018 by Waqar (Vicky)
In my code behind i have a method OnFocusRequested which is called using Interface from my ViewModel when async search button command execute. the problem is that it is working fine when i just debug through each step from code. this code is not work in real time. I believe this is due to async...
20 Aug 2018 by Graeme_Grant
You can do it in code behind however can get messy if you have to do it for multiple controls. The answer is, where you need to use the code in more than one time, to use a behavior rather than code behind to encapsulate the code to avoid the same code in multiple places, reduces errors, and...
11 Dec 2018 by TABiSH777
Hi, you are on right track, you could use Backgroundworker for this purpose with ease, just remember some thing while working with multithread is that, we cannot access UI elements directly from another thread. And as entire code that's executed in Backgroundworker is in another thread we cannot...
13 Dec 2018 by Gerry Schmitz
Yes; you display the (new) .gif in the "ProgressChanged" handler (because it runs on the caller's UI thread versus DoWork which "is" the background worker thread). And you have to call "ReportProgress" (to invoke ProgressChanged) from DoWork; it doesn't run by itself.
6 May 2019 by badarhn
hi all I'm testing the new Microsoft cognitive service example, the code below : GitHub - microsoft/Cognitive-Samples-VideoFrameAnalysis: A library with sample apps for continuous analysis of live video, using the Microsoft Cognitive Services Vision APIs.[^] when I try it returns an exception...
8 Oct 2019 by gouravkaila91
I am calling a c# web API using SSIS script task. The requirement is to pick request data from a table, convert each row to a request, call API for each request and store response in a table. I am looping around all rows of the table and calling API inside loop for one request (row) at a time....
15 Sep 2020 by hmdismail
I was writing some code for automatically generating report and appending it into a spreadsheet. The program runs periodically, each run generates a set of data and inserts it into the first empty row in a specific spreadsheet file. when writing...
2 Nov 2021 by User 15365431
Hi, I am using async/await to fetch a file (createCharge.php) that contains arrays with data inside. Here is my html page that has the that fetches the createCharge.php file arrays data, the createCharge.php also creates a 'hosted_url'...
2 Nov 2021 by Richard Deeming
Your PHP script is returning the URL as text. Your newurl variable will be a string containing the URL. It doesn't have a property called hosted_url, so newurl.hosted_url will be undefined. You haven't declared a variable called hosted_url in...
6 Feb 2023 by Agnib Pyne 2022
Hi All, I am facing a scenario where I am trying to return a list of "ProductTypes". I may need this list in many places in the code and so defined an async method and then calling that method from another async [HttpGet] method and trying to...
N 22 Apr 2024 by Member 16249372
public async Task>> GetStates() { return await _context.States.ToListAsync(); }
15 Apr 2021 by David Deley
Explains program flow when using await in various scenarios
21 Oct 2013 by Marla Sukesh
In this article, you should have basic knowledge of web development and some features introduced in prior versions of .NET Framework, especially ASP.NET features.
6 May 2021 by ipavlu
The goal of the Unified Concurrency is to unify access to different synchronization primitives in object-oriented fashion with one pattern and two interfaces for general and async/await methods.
28 Oct 2014 by dorodnic
Using the await keyword with Expression-Trees
21 Jan 2021 by ipavlu
The goal of the Unified Concurrency is to unify access to different synchronization primitives in object-oriented fashion with one pattern and two interfaces for general and async/await methods.
9 Aug 2014 by Talal Tayyab
The article provides a code first approach to understanding await/async and answers some of the basic questions.
18 Feb 2014 by Marc Clifton
Turns out I was calling the async read before the UI was up and running, so there was no continuation context!
15 Mar 2016 by Patrick Skelton
Hi,I know the internet is littered with fragments of information on this subject, but none of them seems to provide a clear explanation of how you incorporate async functions into synchronous code.I seem to be caught between a rock and a hard place. I have to call an API that provides...
22 Nov 2013 by bowlturner
And why can't you just use System.Threading.Thread.Sleep(10000); in the while (!cancellationToken.IsCancellationRequested) Block?As far as how to wait for the GetRssItems you can use the ContinueWith to call a 'finish' or 'next' I have thisprivate void StartTask(long...
10 Apr 2017 by Swapnil Dhage
This is a helper/utility class that will add a layer of abstraction as well as separation for dispatcher related operations in WPF.
13 Jul 2014 by Sharath C V
A simple async / await example
20 Sep 2015 by Mithun Pattankar
Why build responsive UI? Answer seems obvious that end-user should experience that application doesn’t hang often (for developers POV, a time taking background operation makes it look like hanging). So lets learn building responsive UI using Async Await keywords Visual Studio 2012 introduced a
19 Aug 2015 by Chris875
Please refer below for the several options to call a function with async/await.I put my questions below each option.Lets assume I have a 3rd party Dll and want to call a function of it asynchronously. Despite there is a function description one cannot know what actually happens...
13 Apr 2021 by Nawaz Pasha 2021
I am Using Async Await but still not able to store value or use value outside the function What I have tried: ...
10 Jun 2014 by Vi(ky
HelloI write this code to search the blob items (text files) on the basis of there content. For ex : if I search for "Good", then the files that contains "Good or good" word the name of that files should appear in search result. My code is working but i want to optimize it.class...
1 May 2014 by 123456789igor
Connect success. But how to send bytes, i don't knowprivate readonly Socket _server; public ServerSocket(IPAddress ipAddress, int port) { _server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _server.Bind(new...
15 Feb 2015 by Gaurav_Chaudhary
You can use "Async" and "Await" keywords ,if it's C# 4.5 or above.. Check this out https://i-msdn.sec.s-msft.com/dynimg/IC612215.png[^]Thanks
27 Jul 2018 by Vasilievski
Hi, My issue is the following : I have n Tasks that run in parallel. I want each Task to have its own continuation that uses the result. (Think of a UI update, for each finished task) If I were only using Framework 4.0 Task, I would use the ContinueWith on each task. But I want to use await...
2 Aug 2018 by Richard Deeming
You just need to await the task in the continuation methods. You'll probably also want to wait for all of the continuations to finish in your MainMethod. public async Task ReactToDoSomething(Task task) { int result = await task; // Do something here... } // Same for other "react...
30 Jul 2018 by George Swan
It may be a good idea to restructure your class to facilitate using the Task-based Asynchronous Pattern. I suggest that you change the signatures of some of your methods. Async void methods should be reserved for event handlers. My suggestion would be something like this. public async...
11 Dec 2018 by TheBigBearNow
Hello all, I have a C# WPF application with a database of users. I have it so a user with the correct info can login and depending if they are an Admin or a Customer it will take them to their appropriate menu. Now I want to have a loading .gif while the program is checking the database for the...
13 Dec 2018 by TheBigBearNow
So far I haven’t had luck with my loading gif image when I am loading/checking my database connection I click my login button and I get no errors in my login I start my gif but I also start it in the dowork and progress section im not sure which section is actually right I know not to mess wih...