每个间隔的计时器加载页面 [英] timer loading page on each interval

查看:76
本文介绍了每个间隔的计时器加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在c#中有asp.net网站...



i有一个网络用户控制,我有一个计时器,我正在处理会话超时&这个计时器的间隔为1000毫秒。



我把这个timerUserCtrl放在我的主页上。



但是每一秒页面都会加载,这会降低页面的性能,这意味着它不允许在页面上做任何事情,只要用户想从列表中选择它就得到刷新.....



timeruserctrl

Hi guys,

i have asp.net website in c#...

i have a web user control, in which i have a timer where i'm dealing with the session time out & this timer is with interval of 1000 milliseconds.

and i have placed this timerUserCtrl on my masterpage.

but on every second the page is getting load, which is degrading the performance of the page, means, its not allowing to do anything on the page, as soon as the user want to select from list its get refresh.....

timeruserctrl

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Timer ID="TimerSession" runat="server" ontick="TimerSession_Tick">
                </asp:Timer>
                <asp:Panel ID="PanelSession" Visible="false" runat="server">
                <table class="addgrid">
                <tr style="background-image: removed('images/Background.png'); height: 30px; color: Black;">
                <td>
                Session About Expire
                </td>
                </tr>
                <tr>
                <td>
                
                    <asp:Label ID="lbl" runat="server"></asp:Label><br />
                <center>
                Your Session is about to Expire, Do you want to Continue?
                </center><br /></td>
                </tr>
                <tr>
                <td>
                <div style="padding-removed 200px;">
                    <asp:Button ID="btnContinue" runat="server" Text="Continue"  CssClass="WhiteBlackBtn"
                        onclick="btnContinue_Click" />  
                    <asp:Button ID="btnCancel" runat="server" CssClass="WhiteBlackBtn" Text="Cancel" 
                        onclick="btnCancel_Click" />
                        </div>
                </td>
                </tr>
                </table>
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerSession" />
            <asp:AsyncPostBackTrigger ControlID="btnContinue" />
            </Triggers>
            </asp:UpdatePanel>





timeuserctrl.cs



timeuserctrl.cs

protected void Page_Load(object sender, EventArgs e)
    {
        TimerSession.Enabled = true;
        TimerSession.Interval = 1000;
    }


    protected void TimerSession_Tick(object sender, EventArgs e)
    {
        if (Session["timeout"] != null)
        {
            if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
            {
                string mins = ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalMinutes).ToString();
                if (mins == "1")
                {
                    PanelSession.Visible = true;
                    TimerSession.Enabled = false;
                }
            }
        }
        else
        {
            Response.Redirect("logout.aspx");
        }
    }





Masterpage.master



Masterpage.master

<uc1:SessionTimeoutCtrl ID="SessionTimeoutCtrl1"  runat="server" />
       <asp:ContentPlaceHolder id="CntPLH_MainContent" runat="server">

       </asp:ContentPlaceHolder>





有谁可以帮助我,我怎么能阻止这个页面每秒都刷新。



谢谢



can anyone please help me, how can i stop this page getting refresh on every second.

Thanks

推荐答案

为什么1000毫秒?你设置了这个价值,而不是我们 - 你真的认为用户可以在一秒钟内在页面上做某事吗?我觉得不是这样的,为什么不简单地将价值增加到合理的价值?b $ b

3分钟(3 * 60 * 1000)甚至5分钟?



我会将超时计时器与某种重置结合起来,所以如果用户输入数据或做某事,你就会重置空闲计时器 - 是的,它很难但更正确
so why 1000 milliseconds ? you set up that value, not us - do you really think a user can do something on a page in one second ? I think not

so, why not simple increase the value to something reasonable ? 3 minutes (3 * 60 * 1000) or even 5 minutes ?

I would combine the timeout timer with some sort of 'reset', so if the user is entering data or doing things, you're resetting the idle timer - yeah, its hard, but more correct


这篇关于每个间隔的计时器加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆