嗨調用我想打電話給基於一個時間跨度方法與時間間隔(asp.net C#)
這裏的方法是我的蹤跡
保護無效binddata(對象發件人,EventArgs的){ //我的邏輯在這裏 }
現在我想調用此方法使用C#和asp.net我如何才能做到這一點,每5分鐘
?
謝謝
嗨調用我想打電話給基於一個時間跨度方法與時間間隔(asp.net C#)
這裏的方法是我的蹤跡
保護無效binddata(對象發件人,EventArgs的){ //我的邏輯在這裏 }
現在我想調用此方法使用C#和asp.net我如何才能做到這一點,每5分鐘
?
謝謝
你在ASP.Net ajax控件中有一個定時器控件。
http://msdn.microsoft.com/fr-fr/library/system.web.ui.timer.aspx
它提供了一個postbak
爲例從MSDN:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head runat="server">
<title>Timer Example Page</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
OriginalTime.Text = DateTime.Now.ToLongTimeString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
StockPrice.Text = GetStockPrice();
TimeOfPrice.Text = DateTime.Now.ToLongTimeString();
}
private string GetStockPrice()
{
double randomStockPrice = 50 + new Random().NextDouble();
return randomStockPrice.ToString("C");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" />
<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR />
as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div>
Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
希望這有助於。
使用System.Threading.Timer - http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx。
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(binddata);
myTimer.Interval = 5*60*100;
myTimer.Start();
是的確切這就是我正在尋找的 – Nagu 2009-07-31 08:59:43