开发者

Slow running web page

i created web page with dropdownlist and two gridview and on selectedindex changed event i fill the both of these gridview but in the running the both of gridview take long time to be filled.

Note:one of this gridview i created its datasource by code. here my code snippet:

    protected void _ddlPLCs_SelectedIndexChanged(object sender, EventArgs e)
{
    DataTable dtStatus = new DataTable();

    dtStatus = DBLayer.getMachineNameIPStatusPlCByName(_ddlPLCs.SelectedValue);
    dtStatus.Columns.Add("Status", typeof(String));
    foreach (DataRow row in dtStatus.Rows)
    {
        if (LogicLayer.checkmachineStatus(row["machineIP"].ToString()))
            row["Status"] = "Online";
        else
            row["Status"] = "offline";

    }

    GVStatus.DataSource = dtStatus;
    GVStatus.DataBind();
    if (_ddlPLCs.SelectedValue.Contains('-'))
    {
        _dsPLCs.SelectParameters.Clear();
        _dsPLCs.SelectParameters.Add("PLCID","开发者_开发百科0");
        _dsPLCs.DataBind();
    }
    else
    {
        _dsPLCs.SelectParameters.Clear();
        _dsPLCs.SelectParameters.Add("PLCID", DBLayer.getPlCIDByName(_ddlPLCs.SelectedValue).ToString());
        _dsPLCs.DataBind();
    }            


}

pleas help me


Looking at the code, I think the problem is in this method:

LogicLayer.checkmachineStatus()

I have a hunch that this actually makes a network request to remote machines/devices to determine their status. This is going to be slow, especially if you have machines that might not be online and you have to wait for them to timeout.

If this is the culprit, what you want to do instead is build a service that runs on your server. The service should continually make these checks in the background and update a database table with the results. You probably want to include a timestamp for the last check in the table. It might even be worth inserting rather than updating, so that you have history of when status's were at different values. Your ASP.Net code should then just show the database table.


Profile! Get a trial version of RedGate ANTS and run it against your code.

If you choose line level timings, it will put a number next to each line in the code that will tell you exactly how long each line takes as a % or in milliseconds. Make sure to use wall clock time not cpu time or wait time from your datasource won't be counted properly.

I'd bet your datasource is slow.


You're doing a lot of work here...

A few random thoughts

Networks can be slow -- @Joel had a good point on that one.

One thing to check would be postback -- make sure you're only databinding on selected index changed.

Why aren't you using a 'handles' caluse in your function? Might not be a problem, just curious.

If you change your "status" column header to "online", and then use checkboxes (checked = online, unchecked = off-line, or something like that, you'll just be updating a bool value for each row, instead of a string value.

Something looks odd about how you're re-binding your dropdownlist. Because... You're using the selected value as a parameter in the gridview. Then you're subsequently re-binding the dropdown list, which potentially will result in a different selected value. Which could be causing your gridview to be databound yet again in a circuit. Not sure, as I can't see all of your code.

Anyway, FWIW. Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜