Timer1.Interval = 500

創(chuàng)新互聯(lián)是一家業(yè)務(wù)范圍包括IDC托管業(yè)務(wù),虛擬空間、主機(jī)租用、主機(jī)托管,四川、重慶、廣東電信服務(wù)器租用,四川服務(wù)器托管,成都網(wǎng)通服務(wù)器托管,成都服務(wù)器租用,業(yè)務(wù)范圍遍及中國大陸、港澳臺以及歐美等多個國家及地區(qū)的互聯(lián)網(wǎng)數(shù)據(jù)服務(wù)公司。
Private Sub Timer1_Timer()
Timer1.Enabled = False
Dim ss As String
ss = Format(Now, "HH:mm:ss")
If ss = "12:00:00" Then
'執(zhí)行備份語句
End If
Timer1.Enabled = True
End Sub
還有一個辦法就是可以用SQL自身的功能,在SQL里面可以添加任務(wù) ,設(shè)置周期為每天,時間為12點,到時候執(zhí)行一下備份
MessageBox里的Show里沒有自動關(guān)閉的方法,但是你可以自定義一個MessageBox,MessageBox就是一個窗體,你新建一個窗體Form2,添加一個public屬性message和一個定時器timer1,timer1的interval設(shè)置成你想要的時間,在Form2的Load事件啟動timer1,Timer1_Tick事件里關(guān)閉窗口Me.Close(),然后在需要顯示Messagebox的時候,在主窗口Form1里設(shè)置messge屬性,然后用show方法彈出窗口就可以了。
Form1程序:(添加了一個Button1)
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f2 As Form2 = New Form2
f2.Message = "提示"
f2.ShowDialog()
End Sub
End Class
Form2程序:(添加了一個Label1顯示信息和一個Timer1用于計時,F(xiàn)orm2可以自定義成你想要的樣式,標(biāo)題,按鈕,窗體樣式等)
Public Class Form2
'自定義屬性 顯示提示信息
Public WriteOnly Property Message As String
Set(value As String)
Label1.Text = value
End Set
End Property
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval=3000 '定時3秒關(guān)閉窗口
Timer1.Enabled = True
End Sub
End Class
代碼已在VS2017測試通過。
控制臺調(diào)用Timer和窗體是類似的。首先在項目引用里面加入System.Windows.Forms程序集,然后在代碼頂部引入命名空間:
Imports System.Windows.Forms
在控制臺的Module中聲明一個計時器:
Private WithEvents Timer1 As New Timer()
把計時器的Tick事件靜態(tài)綁定到處理函數(shù)中:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'一些代碼
End Sub
在需要開始計時的地方,修改其Interval、Enabled屬性:
Timer1.Interval = 1000
Timer1.Enabled = True
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Timer1.Interval = 2000(兩秒)
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MsgBox("Hello World")
End Sub
在界面拖一個Button和Timer試試這個效果,在界面雙擊Timer控件,代碼應(yīng)該很明白了
Global.asax C# 全局每隔1小時執(zhí)行任務(wù)
%@ Application Language="C#" %
script runat="server"
void Application_Start(object sender, EventArgs e)
{
// 在應(yīng)用程序啟動時運(yùn)行的代碼
System.Timers.Timer timer = new System.Timers.Timer(900000);
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(doJob);
}
void Application_End(object sender, EventArgs e)
{
// 在應(yīng)用程序關(guān)閉時運(yùn)行的代碼
}
void Application_Error(object sender, EventArgs e)
{
// 在出現(xiàn)未處理的錯誤時運(yùn)行的代碼
}
void Session_Start(object sender, EventArgs e)
{
// 在新會話啟動時運(yùn)行的代碼
}
void Session_End(object sender, EventArgs e)
{
// 在會話結(jié)束時運(yùn)行的代碼。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式設(shè)置為
// InProc 時,才會引發(fā) Session_End 事件。如果會話模式設(shè)置為 StateServer
// 或 SQLServer,則不會引發(fā)該事件。
}
//全局每隔1小時執(zhí)行ChexiaoRenWu();
void doJob(object source, System.Timers.ElapsedEventArgs e)
{
new Maticsoft.BLL.zxy.tbshua_userpublish().ChexiaoRenWu();
}
/script
網(wǎng)站名稱:關(guān)于vb.net定時任務(wù)的信息
標(biāo)題鏈接:http://chinadenli.net/article2/hijdoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、App開發(fā)、定制網(wǎng)站、網(wǎng)站收錄、虛擬主機(jī)、App設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)