0

I have multithreading core C# app, which use external lib (also written in C#) for interaction with webservice. Core app in multiple threads in synchronous mode call method from lib. On load a bit hi than usually, this method execute up to 20-40 and more sec, and sometimes throw timed out exception. Here the code, and marked line, which throw exception

public static class NetCommunicator
{
    static string MakeHttp(string url, string body)
    {
        WebRequest r = WebRequest.Create(url);

        r.Method = body == null ? "GET" : "POST";
        r.Timeout = 60000;

        if (body != null)
        {
            r.ContentType = "text/xml; charset=utf-8";
            byte[] bytes = Encoding.UTF8.GetBytes(body);
            using (Stream s = r.GetRequestStream()) // this line execute up to 20-40 and more sec, and sometimes throw timed out exception
                s.Write(bytes, 0, bytes.Length);
        }

        using (WebResponse httpResp = r.GetResponse())
        using (Stream s = httpResp.GetResponseStream())
        using (StreamReader sr = new StreamReader(s))
            return sr.ReadToEnd();
    }

    public static string MakeHttpPost(string url, string body)
    {
        return MakeHttp(url, body);
    }
}
Dmitriy
  • 177
  • 1
  • 10

0 Answers0