Creating an Asynchronous HTTP Get activity
The WebRequest
class enables us to make an HTTP request in code. Usually, every WebRequest
call requires some time span—several seconds or even minutes. If there is only one request, we can wait for the response. But what are we going to do if we have to make more requests, say 100—every request uses several seconds, and so 100 requests will hang our program.
Then we come up with a good idea: why not use multiple threads with one request for each thread? But it is quite expensive to initialize a thread. If one is writing.NET-managed code, each thread will take up 1MB memory and so 100 threads will use up 100MB memory! Apparently, multiple threads are not an option. So what should we do? In this task, we will create a CodeActivity
that can call a method asynchronously. The key is that our activity must inherit from AsyncCodeActivity
(or AsyncCodeActivity<T>
).
How to do it...
Create the AsyncHttpGet activity:
Add a new code file named
AsyncHttpGet...