public void ExecuteTest2() { var urls = new string[] { "http://www.google.com.br/", "http://www.microsoft.com/" }; urls = urls.Concat(urls).Concat(urls).Concat(urls).Concat(urls).Concat(urls).Concat(urls).Concat(urls).ToArray(); var asyncCallbackSynchronizer = new AsyncCallbackSynchronizer <string>(); Func <AsyncCallback, string, IAsyncResult> begin = delegate(AsyncCallback callback, string url) { var request = HttpWebRequest.Create(url); return(request.BeginGetResponse(callback, request)); }; var synchronizer = new Synchronizer <IEnumerable <IAsyncResult> >(); var callbacker = new ThreadPoolCallbacker <SynchronizationDetails <string>, IAsyncResult>(SynchronizationDetails <string> .Execute); foreach (var url in urls) { var synchronizationDetails = new SynchronizationDetails <string> { Argument = url, Begin = begin, AsyncCallbackSynchronizer = asyncCallbackSynchronizer }; callbacker.Queue(synchronizationDetails); } var results = synchronizer.Execute(callbacker.EnableCallback); var reals = new List <string>(); foreach (var result in results) { using (var response = ((WebRequest)result.AsyncState).EndGetResponse(result)) { reals.Add(response.ResponseUri.AbsoluteUri); } } }
public void ExecuteTest() { var target = new AsyncCallbackSynchronizer <object>(); var request = HttpWebRequest.Create("http://www.google.com"); IAsyncResult actual = target.Execute(request.BeginGetResponse, null); }