Thanks, however Asynchronous is actually a start - stop program. Isn't it possible to check multiple websites at the same time? (I know it's possible with multithreading)
Asynchronous (in programming) is running multiple actions at the same time, as opposed to synchronous (in programming) where each action sits dormant until the preceding actions have completed. Here's a textual diagram for you:
Synchronous log example:
Code:
actionA running
actionA requesting http://example.com/a
// waiting for request
actionA finished.
actionB running
actionB requesting http://example.com/b
// waiting for request
actionB finished.
actionC running
actionC requesting http://example.com/c
// waiting for request
actionC finished.
All actions are complete!
Notice in the synchronous program log, we have to wait for the request before the next request can be sent. That's called blocking. the CPU is twiddling it's thumbs when it could be working. We can keep the CPU busy (like it wants to be) by having it send all those requests at the same time using our asynchronous program:
Asynchronous log example:
Code:
actionA running
actionB running
actionC running
All actions are running!
actionA requesting http://example.com/a
actionB requesting http://example.com/b
actionC requesting http://example.com/c
// waiting for requests...
actionB finished. // note: the order by the end is first-done first-served.
actionA finished.
actionC finished.
All actions completed!
Since making a request is very inexpensive computation-wise, but very expensive time-wise, we can run 3 requests at the same time on the same process. Using extra threads is very expensive compared to running requests asynchronously on the same process. Multi-threading is a way to do asynchronous programming, but certainly not ideal for this.
One problem with asynchronous logic is knowing when all actions are completed. Sure, they complete faster, but the program runs through and doesn't give us the convenience of putting a Console.WriteLine at the end of our program and having it work as expected. Instead, we need to use code for each action, to tell us when it's done, to add something to a pool of completed actions- a list- an array- a map- whatever u call it in C#. Anyway, when ever an action is completed, you trigger some code to run which checks if all actions are in the map/list/array. If they are, then we run the "All actions completed!" part of the program.
So, it's a bit more complex, but learning to master this pattern will greatly benefit your programming career.