简体   繁体   中英

Windows based application to test my ASP.NET application

I want to stress my website with multiple access. To do that i created a windows based application that call 1000 times the website. Unfortunatly it work just for 2 call. This is the code:

    static void myMethod( int i)
    {
        int j = 0;

        try
        {
            string url = "";
            WebRequest wr = null;
            HttpWebResponse response = null;                                
            url = String.Format("http://www.google.com");
            wr = WebRequest.Create(url);
            //wr.Timeout = 1000;
            response = (HttpWebResponse)wr.GetResponse();                
            MessageBox.Show("end");
        }
        catch (Exception ex)
        {
            MessageBox.Show(j.ToString() + "   " + ex.Message);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 1000; i++)
        {
            ThreadStart starter = delegate { myMethod(i); };
            Thread thread = new Thread(starter);
            thread.Start();               
        }

    }

Rather use the Free WCAT Tool to load test your ASP.NET page.

Also view this video [How Do I:] Load Test a Web Application

If you have Visual Studio 2010 Ultimate, see this link

I hope this helps.

By default HttpRequest only allows two connections to the same host. You can change this by setting the DefaultConnectionLimit property.

Try disposing the IDisposable instances (ie the response) before continuing.

static void myMethod( int i)
{
    int j = 0;

    try
    {

        string url = String.Format("http://www.google.com");
        WebRequest wr = WebRequest.Create(url);
        using(HttpWebResponse response = (HttpWebResponse)wr.GetResponse())
        using(Stream responseStream = wr.GetResponseStream())
        {
            //handle response / response stream
        }                
        MessageBox.Show("end");  //this won't scale!!!
    }
    catch (Exception ex)
    {
        MessageBox.Show(j.ToString() + "   " + ex.Message);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM