Link to home
Start Free TrialLog in
Avatar of dnkahn
dnkahn

asked on

C# static class methods

I have the following method in a static class in c#. Many users may potentially access this at the same time, each passing their own values and should get their own return value. On a small scale test this seems to work fine. My question is regarding a concern that if a procedure is static, it should technically only be able to exist in one place and thus either multiple requests to the method would que up in awaiting access if is currently being accessed by another user or worse (but apparently not probable) that the wrong user would recieve a result from another user.

Can anyone clarify this? My inclination is to move such procedures to a standard class.

            private static string HTTPGetRequest(string sURLQS)
            {
                  string tempString = null;
                  int    count      = 0;
                  StringBuilder sb  = new StringBuilder();

                  // used on each read operation
                  byte[]        buf = new byte[8192];

                  // prepare the web page we will be asking for
                  HttpWebRequest  request  = (HttpWebRequest)
                        WebRequest.Create(sURLQS);

                  // execute the request
                  HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                  // we will read data via the response stream
                  Stream resStream = response.GetResponseStream();

                  do
                  {
                        // fill the buffer with data
                        count = resStream.Read(buf, 0, buf.Length);

                        // make sure we read some data
                        if (count != 0)
                        {
                              // translate from bytes to ASCII text
                              tempString = Encoding.ASCII.GetString(buf, 0, count);

                              // continue building the string
                              sb.Append(tempString);
                        }
                  }
                  while (count > 0); // any more data to read?

                  // print out page source
                  return sb.ToString();
            }
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial