如何使用ASP.NET SignalR实现全局计时器? [英] How to implement a Global Timer using ASP.NET SignalR ?

查看:95
本文介绍了如何使用ASP.NET SignalR实现全局计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我建立一个有一个区域的拍卖网站,我需要为每个可用于实时招标的产品实施全球计时器(比如10秒)。每当用户点击提交按钮时,计时器必须重置,并且每当计时器到期时,最后一个已经出价的用户必须赢得产品。我从SQL Server数据库中名为Table的表中获取产品相关信息。因此,每当用户赢得产品时,必须使用变量状态将该产品状态设置为true(暗示该产品已售出)。请分享我如何实现它,这是我正在使用的代码。



 <%@     Page    语言  =  C# < span class =code-attribute>   AutoEventWireup   =  true    CodeBehind   =   index.aspx.cs   继承  =  Timer.index   %>  

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > < / title >
< style 类型 = text / css >
paneldesign
{
width 100px;
height 150px;
text-align center;
border-radius 15px;
}
productlist li
{
display inline;
float left;
margin- left 10px;
margin-bottom 10px;
}
< / 风格 >
< span class =code-keyword>< / head >
< < span class =code-leadattribute> body >
< 表格 id = 表单 runat = server >
< div >
< asp:ListView DataSourceID = sqldtsrcpdt ID = pdtlst runat = server >
< LayoutTemplate >
< ul class = productlist >
< asp:PlaceHolder ID = itemPlaceholder runat = 服务器 >
< / asp:PlaceHolder >
< / ul >
< br / >
< / LayoutTemplate >
< ItemTemplate >
< li >
< asp:Panel ID = pnlpdt CssClass = paneldesign 宽度 = 200px 高度 = 150px BorderColor = 黑色 < span class =code-attribute> < span class =code-attribute> BorderWidth = 3px runat = < span class =code-keyword> server > < br / >
< asp:标签 ID = lblpdtid runat = server 文字 =' <% #Eval( P_ID%> ' 可见 = 错误 > / asp:标签> < ; br / < span class =code-keyword>>
< asp:Label ID = lblpdtname runat = server Text =' <% #Eval( 名称%> ' > < < span class =code-leadattribute> / asp:Label > < < span class =code-leadattribute> br / >
< asp:标签 ID = lbltmr runat = server ForeColor = 红色 文本 = 计时器 > < / asp:Label > < br / >
< asp:按钮 ID = btnsubmit runat = 服务器 文本 = 提交 OnClick = btnsubmit_Click / >
< / asp:Panel >
< / li >
< / ItemTemplate >
< / asp:ListView >
< asp: SqlDataSource ID = sqldtsrcpdt runat = server ConnectionString = <% $ ConnectionStrings:DtConStr %>

< span class =code-attribute>
SelectCommand = SELECT [P_ID],[Name],[Status] FROM [Table] >
< / asp:SqlDataSource >
< / div >
< / form > ;
< / body >
< / html >





http://postimg.org/image/he7upat09/ [ ^ ]

解决方案

ConnectionStrings:DtConStr %>

< span class =code-attribute> SelectCommand = SELECT [P_ID],[Name],[Status] FROM [Table] > ;
< / asp:SqlDataSource >
< / div >
< / form >
< / body < span class =code-keyword>>
< / html >





http://postimg.org/image/he7upat09/ [ ^ ]


In my building an Auction website which has an area, Where I need to implement a global timer (say for 10secs) for each products which are available for live biding. Whenever a user clicks the button "Submit" the timer must get reset and whenever the timer get expired then the last user that has made a bid must win the product. I'm fetching Product related Information from a table named "Table" from SQL Server database. So, whenever a user wins the product then that products status must be set to true (implying that product is sold) using a variable "Status". Please share how can I achieve it, Here's the code that I'm using.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="Timer.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .paneldesign
             {
  	            width:100px;
   	            height:150px;
   	            text-align:center;
   	            border-radius: 15px;	
             }
        .productlist li
             {
                display:inline;
                float:left;
                margin-left:10px;
                margin-bottom:10px;
             }
    </style>
</head>
<body>
    <form id="form" runat="server">
    <div>
        <asp:ListView DataSourceID="sqldtsrcpdt" ID="pdtlst" runat="server">
            <LayoutTemplate>
                <ul class="productlist">
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server">
                    </asp:PlaceHolder>
                </ul>
                <br />
            </LayoutTemplate>
            <ItemTemplate>
                <li>
                    <asp:Panel ID="pnlpdt" CssClass="paneldesign" Width="200px" Height="150px" BorderColor="Black"                                               BorderWidth="3px" runat="server"><br />
                        <asp:Label ID="lblpdtid" runat="server" Text='<%#Eval("P_ID") %>' Visible="False">/asp:Label><br />
                        <asp:Label ID="lblpdtname" runat="server" Text='<%#Eval("Name") %>'></asp:Label><br />
                        <asp:Label ID="lbltmr" runat="server" ForeColor="Red" Text="Timer"></asp:Label> <br />
                        <asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" />
                    </asp:Panel>   
                </li>
            </ItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="sqldtsrcpdt" runat="server" ConnectionString="<%$ ConnectionStrings:DtConStr %>" 

            SelectCommand="SELECT [P_ID], [Name], [Status] FROM [Table]">
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>



http://postimg.org/image/he7upat09/[^]

解决方案

ConnectionStrings:DtConStr %>" SelectCommand="SELECT [P_ID], [Name], [Status] FROM [Table]"> </asp:SqlDataSource> </div> </form> </body> </html>



http://postimg.org/image/he7upat09/[^]


这篇关于如何使用ASP.NET SignalR实现全局计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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