Contenido del Curso
Introduction to .NET with C#
Introduction to .NET with C#
2. Asynchronous Programming and Introduction to Web Services
3. Introduction to Databases with .NET
What is Asynchronous Programming?
So far, the code we had been writing was purely synchronous, which means that each task was performed one by one, and almost never any tasks were running at the same time.
If we have some code like the following:
Each method will be executed one after the other. So task2
will not start before task1
is finished. Similarly, task3
will not start before task2
is finished.
It is acceptable in basic programs, but when we are making big applications, we need to make sure that one task does not block the execution of another.
For-example, in web browsers, one tab can be playing music, while in the other tab, the user can be browsing social media. This kind of multitasking is possible through Asynchronous Programming.
Asynchronous Programming is a method of programming that allows us to create programs that can execute multiple tasks at the same time. This helps in making the applications more efficient and responsive by executing multiple tasks.
C# provides us with some useful tools for asynchronous programming. We will look at how to use them in the next chapter.
Benefits of Asynchronous Programming:
- By executing time-intensive tasks concurrently, we can effectively prevent the main program from becoming blocked. This concurrent approach ensures that the application remains responsive, even when engaged in resource or time intensive;
- Increased responsiveness and quicker execution provide smoother user experience;
- Instead of executing all operations in a single queue, your application executes them concurrently. This way, it gains the capability to handle a larger number of concurrent operations, making it more scalable. For example, you might have an application where many clients (users) need to be served simultaneously.
Disadvantages of Asynchronous Programming:
- By employing asynchronous programming in your code, you can potentially increase the complexity of the code, making it difficult to manage and debug;
- If you make one part of your code asynchronous, most of your code tends to become asynchronous as well.
¿Todo estuvo claro?