[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# static class methods

Posted on 2006-07-05
1
Medium Priority
?
514 Views
Last Modified: 2007-10-18
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();
            }
0
Comment
Question by:dnkahn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
dstanley9 earned 150 total points
ID: 17046737
No, static _methods_ are OK, it's static _variables_ you need to be careful of in multithreqading environments. The static methods will create local varaibles in the context of the running thread, so there are no issues with synchronization.  I don't see you using and members, only local variables, so you're OK.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question