Click here to Skip to main content
15,886,069 members
Everything / Async

Async

Async

Great Reads

by Dev Leader
Problem with async void and a solution for it
by ChRi$m0rG@N
An article about an omni directional Arduino Yun robot, and an alternative .Net implementation of CmdMessenger
by Noah L
Beware the data race sneak attack.
by Nejimon CR
Implement WCF web service access from WPF with busy indicator and premature cancellation feature without using delegates, background worker, or separate event procedure

Latest Articles

by Federico Alterio
Convert an Event-based API to an awaitable pattern API
by Dev Leader
Secret of Task EventHandlers
by Dev Leader
Problem with async void and a solution for it
by Pete O'Hanlon
In the previous article, I started describing how I had built a more complex TypeScript web application that retrieves data from a separate API and displays the data in a relatively visually pleasing manner.

All Articles

Sort by Score

Async 

6 Feb 2023 by Dev Leader
Problem with async void and a solution for it
2 Apr 2015 by ChRi$m0rG@N
An article about an omni directional Arduino Yun robot, and an alternative .Net implementation of CmdMessenger
30 Nov 2015 by Nejimon CR
Implement WCF web service access from WPF with busy indicator and premature cancellation feature without using delegates, background worker, or separate event procedure
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
28 Jan 2021 by Shaun C Curtis
A practical walkthrough of Async Programming in DotNetCore
18 Mar 2016 by Richard Deeming
Task.Delay will create a new Task (technically, a DelayPromise) and a Timer:Task.Delay | Reference Source[^]However, in your example, it will do this once per second. It won't "whiz round" creating new objects in a tight loop, because the await ensures that the rest of the method doesn't...
10 Dec 2021 by George Swan
How asynchronous streams can improve efficiency and reduce response times in applications
25 Oct 2011 by Espen Harlinn
It's IE that limits the number of connections to your server:http://blogs.msdn.com/b/ie/archive/2005/04/11/407189.aspx[^]Best regardsEspen Harlinn
11 Aug 2020 by Shaun C Curtis
A guide to async programming in Blazor
29 Sep 2021 by tugrulGtx
CLOCK caching (LRU approximation) with O(1) cache hit, up to N asynchronous O(1) cache misses
27 Nov 2012 by Volynsky Alex
Hi iron,For exampple it is possible to do with C++/Qt....Sometimes, it's necessary to execute some queries to database in asynchronous way (multi-thread), for example to avoid to freeze a GUI if a query is too long to execute.To make easier to work with asynchronous queries, QxOrm library...
22 Feb 2015 by Elliot Balynn
Introduction This article is about the internal implementation of await/async functionality. It doesn’t cover the high level functionality, but aims to explore the internal implementation. If you would like to familiarise yourself with the overall functionality first there is an in depth artic
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...
31 Jan 2017 by Cathy Wun
This is the first part of Building an Employee Tracker using AngularJS and ASP.NET Web API Series.
29 Dec 2017 by ipavlu
Optionally awaitable simple to use Concurrent Priority Queue.
16 Jan 2018 by Richard Deeming
This is one of the big problems with async void methods - the method returns before it has completed, and the caller has no way of knowing that the method is still doing work. The Application class raises the Startup event. When the handler returns - at the first await call in your example - it...
23 Jul 2020 by honey the codewitch
Explore adapting Socket's async model to a task based one and adding some awaitable socket operations to your projects
17 Jan 2013 by Sergey Alexandrovich Kryukov
Here is what I can see: you are using Thread.Sleep. I don't have v.4.5 to test it, but let's see: it's explicitly documented, that the invocation of async methods does not create a new thread; using them does not require multithreading:...
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...
4 Mar 2015 by Richard Deeming
If you can change the ProcessListings method to do its work asynchronously, and return a Task, then this would be simple:public async Task ProcessAsync(bool isForced){ var prevStatus = Status; Status = SchedulerStatus.Processing; await ProcessListingsAsync(); Status =...
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...
14 Sep 2016 by ZurdoDev
As mentioned in comments the server should handle that for you. If you find that your server cannot handle the load then you implement load balancing or some other technique but your code will stay the same, essentially.
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 Mar 2019 by Bohdan Stupak
Simple pitfall where C# developers trying out F# might fail when writing async code
26 Aug 2020 by Richard Deeming
The return type of an async function will need to be Task or ValueTask, so your delegate type will be either Func> or Func>. The function runner effectively doesn't care whether or not the function is async - it just...
6 Jul 2021 by Gerd Wagner
The evolution of asynchronous programming in JavaScript: callbacks, promises, async/await
31 Jul 2021 by Jason Sultana
Implement a “top-level” async function in Node when there is no async main method
23 Sep 2011 by Herman<T>.Instance
I can understand why no one gave an anwer!This is pretty hard but I managed :)In the HTTPModule You first register the begin and end method.In the begin method the wcf begin method was called and the answer return to the endmethod of the httpmodule which called the endmethod of the wcf...
29 Jun 2012 by William2011
Hi,I'm trying to use two asynchronous methods in one method.the methods look like this:class Sender{ public static void sendMessage(Int32 uniqueRequestID, Int32 requestCode}class Receiver : IReceiver{ public override void onAnswerReceive(Int32 uniqueRequestID, Answer...
2 Jul 2014 by Kornfeld Eliyahu Peter
You have to push all your task into an array of tasks upon creation. At the point where you want to wait to them add call to Task.WaitAll[^] method...
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
7 Nov 2014 by DamithSL
Read Async with await do not work. Why?[^]
8 Nov 2014 by Snesh Prajapati
Following is the code which we should be writing to fulfill your conditions: async Task> Counting() { Console.WriteLine("....something else...Started"); List nums = new List(); for (int i = 0; i...
8 Jan 2016 by Dave Kreskowiak
You mean something like this? What's better about this method is you get to handle exceptions as well as timeouts quite cleanly. private async void StartButton_Click(object sender, EventArgs e) { try { string message; ...
19 Mar 2016 by Patrick Skelton
Hi,I thought I was beginning to understand the new async/await keywords. Then I had cause to write something like the code below, similar to an extremely slow game loop, which simply runs continuously until a flag changes value. This is a much-shortened version of the code:public...
22 Mar 2016 by Patrick Skelton
Hi,I have a class which contains a function that needs to be called asynchronously at a later time. Similar to this:public class MyClass{ public Task SomeFunctionAsync() { // Do a long-running thing... }}I actually have a few of these classes, and I am...
6 Sep 2016 by Bernhard Hiller
Returning a simple result asynchronously is a pain.Following code compiles:public async Task, bool>> GetQuestionOptions(List studsList){ var tmp = new Tuple, bool>(new List(), true); return await Task.FromResult(tmp);}The magic is in...
13 Sep 2016 by Richard Deeming
The WebService class pre-dates the Task Parallel Library, and knows nothing about async tasks.However, it does support the older IAsyncResult / APM pattern:How to: Create Asynchronous Web Service Methods[^]And it's possible to implement that pattern using a Task:Implementing the APM...
14 Nov 2016 by Dave Kreskowiak
Google for "MVC Controller async".
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...
13 Dec 2016 by Jochen Arndt
MFC classes are not thread safe but std::async will probably create a new thread to execute the function which is then the reason for the access violation when calling a MFC member function from a different thread.The common solution with MFC classes is posting user defined messages...
16 Aug 2020 by Garth J Lancaster
Quote: I have some code that is connected to a websocket. And it can execute less than .0005 ms so it can be called basically instantly multiple times. I would be looking at decoupling the receive vs processing logic - receive the data, queue...
26 Aug 2020 by Patrick Skelton
I have a class that has a function that runs the supplied delegate, which is of type Func, as shown in the following code. public static class FunctionRunner { public static int RunSuppliedFunction( Func aFunctionReturningInt ) =>...
26 Aug 2020 by Patrick Skelton
With the helpful nudge from @Richard Deeming, I have got the code compiling like this (which also moves a step closer to showing what the point of all this is): public static class FunctionRunner { public static async Task...
1 Oct 2020 by Richard Deeming
The result of an async function will be a Promise. You either need to await it, or use the continuation to read the result. You should also avoid calling the function twice. Call it once and store the result in a variable. async function...
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 Sep 2011 by Herman<T>.Instance
Hello everyone,I have a lovely problem.I have an Asynchronous HTTPModule and that module calls an Asynchronous WCF service.In module I dig up several values from Session[]But when 1 value is string.IsNullOrEmpty I do not want to make the call to the asynchronous wcf service but I...
25 Oct 2011 by Trekstuff
Hi all,I have a main parent page with several "widget" iframes. ClientSide JavaScript sets SRC attribute of these iframes so they can load at the same time. The problem is: if one of the iframes (they're all loaded from the same IIS server and really are ASPX pages) is taking a lot to load -...
25 Oct 2011 by ShacharK
I have multiple clients, and I'm trying to send to each and every one of them some messages, using async callbacks (when a message is sent, next message is dequeued). I wanted to ask if when using Async callbacks, are they using the thread pool? or exceeding it? or anything like that.Can...
25 Oct 2011 by Rob Philpott
If you mean by async callbacks the asynchronous programming model (BeginInvoke, EndInvoke etc.) then the threadpool is generally used.http://msdn.microsoft.com/en-us/library/ms228963.aspx[^]
15 Nov 2011 by larssy1
Hey everyone,I'm currently working a little project, however i'm encountering an problem.I have to obtain values from an xml file, and the single row which exists in the sheet, needs to be copied to an already existing and filled class.However, in every way i try, the class keeps...
29 Jun 2012 by Sergey Alexandrovich Kryukov
Let me continue from the question I asked in my comment to the question.I think that asynchronous API flourished when threads were not a commonplace; and these days they finally lost their purposes, except supporting some legacy. Using purely synchronous approaches with all blocking call but...
9 Oct 2012 by Paulo Morgado
Sometimes, for demo or testing purposes, I need a synchronization context that behaves like the user interface ones but doesn’t force me to build applications with a user interface and the TPL Dataflow Library seemed like a good option to implement such synchronization context.
30 Oct 2012 by gaurish thakkar
I am tying to upload a image file using asp async file upload.protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { if (AsyncFileUpload1.HasFile) { string filext =...
30 Oct 2012 by gaurish thakkar
nothing is haapening in firefox AND CHROME but it is working in IE
27 Nov 2012 by irol
Hello,I need to execute sql queries in asynchronous manner.Any examples ?Thanks in advice.Irek.
17 Jan 2013 by sjelen
It's hard to give a solution without knowing your exact network setup.Most common case when connecting through a router is that your local network is behind NAT and it makes direct connection from Internet to local computer impossible.Solution depends on your router capabilities: you would...
17 Jan 2013 by animares
I just want to use socket to connect to a remote computer and send the message (TCP chat). What do you suggest? Port forwarding or put the computer in DMZ zone?
17 Jan 2013 by MeSaNei
Hello,Why my form does not respond on user actions with following code?using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using...
8 Mar 2013 by Artem Smirnov
Testing Async Requests, Mocking Async Methods with New Ivonna
27 Mar 2013 by AghaKhan
This is very unusual behavior, but there is a solution. There is need an extra parameter for ContinueWith call.imtask.ContinueWith(t => { if (t.IsFaulted == false) { WriteableBitmap writeableBmp = t.Result;...
4 Aug 2013 by Member 10188113
I have node js files restservice.js and mysql.jsIn mysql.js i have two functions as elementlevelpricing and pricingdetailIn restservice.js i have api which has the code as :var workload = req.body; var workloadinfo = { workloadId: workload.workloadId, ownerId:...
11 Oct 2013 by PEIYANGXINQU
My codes is here,It run well in my localhost,but after publish it is wrong .I catch the exception,It says that have a error called " System.Threading.Tasks.Task.Wait Method (Int32, CancellationToken) in System.Threading.Tasks.~1.get_Result()",How to fix the code?My .net framework is 4.0,not...
11 Oct 2013 by Ron Beyer
According to this page[^] HttpClient.PostAsync is not supported in .NET 4 (only 4.5).In fact, the entire HttpClient doesn't exist in 4.0. So I'm not sure how you are running it on 4.Edit:Unless you are using this library[^]?
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.. :)
18 Dec 2013 by Member 8028486
Please help me to understand C# async function calls like BeginAcceptConnection() from TcpListener.
19 Dec 2013 by Simon Lee Shugar
You will need to be more specific in what you are asking.Try MSDN or looking for tutorials within code project.http://msdn.microsoft.com/en-us/library/6y709t3b(v=vs.110).aspx[^]
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.
11 Feb 2014 by chronodekar
I've been tasked to write a script which will run on the parse.com cloud ( https://parse.com/docs/cloud_code_guide[^] ) and update the parse-database as needed based on a 3rd party source (another website, that needs to be monitored). The only language supported on parse.com is javascript -...
11 Feb 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Refer following resources.1. JavaScript Guide[^]2. Getting Started with Parse[^]3. Using the Parse JavaScript SDK? Be Careful![^]4. Example of a Parse.com JavaScript application with offline support[^]5. Parse.com Javascript Guide[^]
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: " +...
13 Apr 2014 by Zamanis
Im trying to create a C++ Runtime compoment to use in c# windows store app project;I Created a new project C++ -> Windows Store App -> Windows Runtime Component.The new project has default class1.This is what i m trying to do:Class1.h:public ref class Class1...
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 May 2014 by ckumaresanmba
Sample codestatic void Main(string[] args){ ServiceReference1.BankCardSoapClient s = new ServiceReference1.BankCardSoapClient(); Task[] tasks = new Task[]{ Task.Factory.StartNew(() => s.test(), TaskCreationOptions.LongRunning), Task.Factory.StartNew(() => s.test2(),...
4 Jun 2014 by Member 9500954
Hey!I working on a hotel search engine with gathers the result from a API of ExpediaI am displaying the first 15 results and then I am starting a async function to save the rest of the results in a database.Async Function RequestMoreHotels(ByVal city As String, ByVal country As String,...
5 Jun 2014 by Member 9500954
I think I am doing something wrong with the async await funcionality:Anyway, I changed the code toPublic Function RequestMoreHotels(ByVal city As String, ByVal country As String, ByVal countryCode As String, ByVal RegionID As String, ByVal checkInDate As String, ByVal CheckOutDate As...
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...
2 Jul 2014 by mathiazhagan01
I have 2 AsyncTask, one was nested inside other in the loop, I want to invisible the progress bar and also do other functions after both AsyncTask is finished. I don't know how to do that? Please help me.public class GalleryFragment extends Fragment { ProgressBar...
15 Jul 2014 by Jason R. Woods
Looks like all you need to do would be to changeIAsyncOperation^ StreamToBitmap(IRandomAccessStream^ fileStream)to:IAsyncOperation^ Class1::StreamToBitmap(IRandomAccessStream^ fileStream)in your Class1.cpp file.
29 Jul 2014 by hbbiao
I am new to reactor pattern , i know that this pattern can solve the per client per thread problem in traditional block socket programming ,my question is that the virual function handle_input will be called by the event dispatcher to indicate that we can read now ,but is the program logic...
7 Aug 2014 by Yannick Brodard
So I have this command :public DelegateCommand GenerateReportForAllClientsCommand { get; set; }public bool CanExecuteGenerateReportForAllClients(){ return true;}public async void GenerateReportForAllClientsExecute(){ if (ClientList.Count
10 Aug 2014 by Yannick Brodard
By searching the web, I found a convenient answer to my problem.I had an other async / await in my GeneratePdfReportAsync method, and I've discovered that a Task or Task object need the UI Thread to be available. But in this case for this method, I didn't need the UI Thread, but it was...
7 Oct 2014 by Nosey Parker
TcpClient.BeginConnect with timeout
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...