-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Windows-only Class WebAsyncClient #206
base: master
Are you sure you want to change the base?
Conversation
@Sophist-UK I like the evented approach, that'll be nice to add to VBA-Web, and the switch to I look forward to seeing this develop. |
@timhall Using a full wrapper is a trade off - ease of use for ease of maintenance. But the only maintenance is to keep the wrapper properties in line with changes to WebClient which is not too onerous IMO. |
The reason you need a Delegate is that events are only passed for the object which is referenced by the WithEvents variable, not for other instances of the same class which are held in e.g. a collection. This is the only way that I know of to raise events from multiple instances. |
I am also pondering whether to add a request queuing mechanism to this class - to limit the number of simultaneous requests as at present there is no limit to the number that you can kick off in quick succession which could create issues either with the number of broadband router connections or Windows / Router half-open connections or trigger limits on the server (for e.g. anti-DoS). This would work by only initiating the new request if there are <= limit number of requests already open and kicking off a new one when the previous one finishes. (Also have an ability to add Priority requests to run next by putting them at the front of the queue whilst normal requests go to the back of the queue.) Default number of simultaneous requests would be 8 - being the limit used as standard by IE10/11 and Opera 10 - so unlikely to trigger DoS actions on a server. |
6f7f23c
to
b012ab1
Compare
I have reloaded this branch with a modified version which includes the above enhancements plus checks for duplicate RequestRef and an Exists function. |
This is an alternative way of submitting asynchronous Web calls to WenAsyncWrapper. The WebClientAsync class truly wraps the WebClient class, providing the same methods and properties and passing them through to WebClient. It is inspired by WebAsyncWrapper and tries to make async calls as compatible as possible with WebClient. It also provides an ExecuteAsync method that kicks off a web call (using another WebClientAsyncInstance class) and passes results or errors back to the caller using Events. Like WebAsyncWrapper it relies on WinHttpRequest and so is Windows only (or at least until someone writes a WebHttpRequest compatible class for Mac like Tim has done with the Dictionary class). Because it returns results using Events, it can only be called from another Class module, however it is the authors belief that anyone doing Async calls is likely to be using classes anyway. Having written and undertaken some simple tests, I am submitting this code for early review. Once I have written the real code that will use it and ironed out any bugs found, and rounded out the comments I will let you know it is ready for merging.
b012ab1
to
b1aad8e
Compare
Hello Sophist, Hope the answers are not too trivial.... |
@gerald2545 I sent you some explanation and sample code by email. |
Hi, |
My pleasure. I would like other people to enjoy the benefits of my coding. |
This is an alternative way of submitting asynchronous Web calls to WenAsyncWrapper.
The WebClientAsync class truly wraps the WebClient class, providing the same methods and properties and passing them through to WebClient. It is inspired by WebAsyncWrapper and tries to make async calls as compatible as possible with WebClient.
It also provides an ExecuteAsync method that kicks off a web call (using another WebClientAsyncInstance class) and passes results or errors back to the caller using Events.
Like WebAsyncWrapper it relies on WinHttpRequest and so is Windows only (or at least until someone writes a WebHttpRequest compatible class for Mac like Tim has done with the Dictionary class). Because it returns results using Events, it can only be called from another Class module, however it is the authors belief that anyone doing Async calls is likely to be using classes anyway.
Having written and undertaken some simple tests, I am submitting this code for early review. Once I have written the real code that will use it and ironed out any bugs found, and rounded out the comments I will let you know it is ready for merging.