c# - HttpWebResponse get mixed up when used inside multiple threads -


will I have a thread that data from the web service in my application I actually am open I just a URL and XML I get the output. I have some formulas that constantly do this but with different URLs. Sometimes the results are mixed XML output is not related to a thread's URL, but it is for any other thread's URL.

In each thread, I will create an example of class GetWebPage and call method to get this example. This method is very simple and mostly based on codes from MSDN documents. (String Upyogkrtaagent, String url, String user, String pass, Int timeout, Int Reedraittaimet, Vebhaiderclekshn WHC) {string buffer = string. Empty; HttpWebRequest myWebRequest = (HttpWebRequest) WebRequest.Create (url); If (! String.IsNullOrEmpty (userAgent)) myWebRequest.UserAgent = userAgent; MyWebRequest.Timeout = Timeout; MyWebRequest.ReadWriteTimeout = Readonly Timed Out; MyWebRequest.Credentials = New network credentials (user, pass); String [] header = whc.AllKeys; Foreign currency (strings in header) {myWebRequest.Headers.Add (s, whc.Get (s)); } (Using HttpWebResponse myWebResponse = (HttpWebResponse) myWebRequest.GetResponse ()) using {(stream ReceiveStream = myWebResponse.GetResponseStream ()) {encoding encode = Encoding.GetEncoding ( "utf-8"); Read Stream Reader Stream = New Streamminder (Receivestream, Encoded); // Read 1024 characters at a time [read] = New four [1024]; Int count = readstream.Read (Read, 0, 1024); Int break_counter = 0; While (count & gt; 0 & amp; amp; amp; and & amp ;; break_counter & lt; 10000) {string str = new String (read, 0, count); Buffer + = str; Count = readStream.Read (Read, 0, 1024); Break_counter ++; }}} Return buffer;

As you can see that I do not have any public assets or no other shared resources. At least I do not see anyone url is the service that I call on the Internet and the buffer is the XML output from the server just like I said that I 12) examples of this class / method in some thread and sometimes buffer do not URL a single thread yarn but another.

Edit

I added

  System.Net.ServicePointManager.DefaultConnectionLimit = 25;  

And now it works for some time without any error programm.

"itemprop =" text ">

Your method is completely thread-protected.

You may have a problem with the code called method.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -