0

i have this method:

        private void sendSms(object url)
    {
        var Url = url.ToString();
        webRequest = WebRequest.Create(Url);
        //            webRequest.BeginGetResponse(this.RespCallback, webRequest);
        webResponse = webRequest.GetResponse();
        // End the Asynchronous response.
        var stream = new StreamReader(webResponse.GetResponseStream());
        var response = stream.ReadToEnd().ToString();
        if (response.Contains(Config.ValidResponse))
        {
            var queryString = HttpUtility.ParseQueryString(webRequest.RequestUri.Query);
            OnMessageAccepted(this, new MessageAcceptedEventArgs(queryString["SN"], "n/a"));
        }
        else
        {
            OnMessageAccepted(this, new MessageAcceptedEventArgs("", "n/a"));
        }
    }

which i call inside a loop like this

While (true)
{
    Send(url);
    sleep(400);
}

Problem is after couples of hundreds of calls like 500 or 600 the performance of the calls gets slower and slower if i restart application it start so fast and good but then start slowing down ! i was wondering if there is any buffer or cache i should clear every now and then to make it stay fast ?

ps: i developed the server so im sure the server doesnt slow it down plus i tried that with different kind of server implementation that i developed and developed by others.

thanks in advance.

Stacker
  • 8,157
  • 18
  • 73
  • 135
  • 1
    Hi, If you want to put current process in sleep don't use sleep(400) it will just wait, regarding the .NET documentation only if you put sleep(0) then other process can use your processor, otherwise it will just wait and will not give space for other threads. I hope this helps. – Senad Meškin Jan 24 '11 at 14:30
  • i have to make it wait i cant send all the messages without waiting in between – Stacker Jan 24 '11 at 14:44
  • I know what are you saying, but other processes are waiting, you can send them using timer or something but always use sleep(0) in order to give space to other processes on your server. – Senad Meškin Jan 24 '11 at 15:30

1 Answers1

1

You need to dispose the response and response stream using using blocks.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964