私は貧弱なロード テスターを書いており、リソース (スレッド プール) を正しく管理していると思っていましたが、次のコードを実行すると、WebClient.DownloadStringAsynch への呼び出しで OutOfMemoryException が発生します。
.net4.0 を使用していますが、4.5 に移行できます。
質問:
- 修正は何ですか?
- HttpWebRequest を使用して、その非同期を webclient の代わりに送信するにはどうすればよいですか?
await を使用して .net 4.5 を使用するのはどうですか (.net4 が非同期呼び出しでスレッドを管理する方法との違いはありますか?
static void Main(string[] args) { System.Net.ServicePointManager.DefaultConnectionLimit = 200; while (true) { for (int i = 0; i < 100; i++) { Task.Factory.StartNew(LoadTestAsynchNET40); } Console.WriteLine(".........................sleeping..............................."); Thread.Sleep(2); } } static void LoadTestAsynchNET40() { string url = "http://mysrv.com/api/dev/getthis?stuff=thestuff" + "&_=" + DateTime.Now.Ticks; // <--- somtimes throws here... using (var client = new WebClient()) { DateTime dt1 = DateTime.Now; client.Headers["Accept"] = "text/xml"; client.DownloadStringCompleted += DownloadStringCompleted; Console.WriteLine(DateTime.Now.ToString("ss:fff") + ", Sent Ad Request..."); client.DownloadStringAsync(new Uri(url), dt1); //<---throws here... } } static void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { Console.WriteLine("Received reponse..."); }