1

我在Global.asax中有大約10個應用程序變量計數器,用於顯示這10個不同類別的文件下載。現在我想在特定時間插入/更新這些計數器的值(由於應用程序重新啓動重置計數器時重置計數器)每天晚上11點說,並更新計數器。在當天的特定時間向SQL Server表插入/更新數據

怎麼辦?有任何想法嗎?

Global.asax

void Application_Start(object sender, EventArgs e) 
{ 
     Application.Add("MGM",0); 
     Application.Add("PC",0); 
     Application.Add("NC",0); 
     Application.Add("TC",0); 
     Application.Add("PGC",0); 
} 

shortCode參數是全球性的會議從Global.asax文件的名稱。我正在通過獲得櫃檯並相應增加。

Download.aspx.cs頁:

private int GetCount(string shordCode) 
{ 
    int count=0; 
    count = Convert.ToInt32(Application[shortCode]); 

    lock (Application[shortCode]) 
    { 
     Application[shortCode] = ++count; 
    } 

    return count; 
} 

幫助感激..!

回答

1

您可以使用下面的代碼。

public void GetCurrentTime() 
    { 
     int hours ; 
     hours = DateTime.Now.TimeOfDay.Hours; 
     //when time is 23Hrs of the day 
     if (hours == 23) 
     { 
//  UpdateCounter here   
     } 
    } 
+0

好的,謝謝我會試試... – 2012-08-11 10:14:53

相關問題