Preferred Multithreading in C# ASP.NET

Parallel execution has been one of the core techniques of programming languages that enables and stabilizes the heavy orchestrated flow of information across information management systems. All Object Oriented Programming languages provides couple different ways to implement this to function smoothly under heavy and stressful load 🙂

A better way was introduced in C# which is called – Asych / Wait with ASP .NET 4.5 as an alternative to Multithreading or other ways to allow parallel execution where we need not want to wait for program execution to wait.

Example:

You define the method with aysn and Task decorator as shown below –

public async Task DownloadHtmlAsync (String url)

{

var webClient = new WebClient();

var content = await webClient.DownloadStringAsync(url);

using (var streamWriter = new StreamWriter(@”C:\test\test.html”))

{

await streamWriter.WriteAsyn(content);

}

}

You then use the Asyn specific function and then use the await keyword to ensure that those blocking tasks are not waited by succeeding lines of code.

Add a Comment

Your email address will not be published. Required fields are marked *