1

私の Visual Basic .NET フォームで、X 間隔ごとに関数を実行するようにチェックすることは可能ですか?

4

3 に答える 3

4

Timerクラスを確認してください。

Public Class Form1
    Private T As Timer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        T = New Timer()
        AddHandler T.Tick, AddressOf TimerTicker
        T.Interval = (1000 * 3) 'Every 3 seonds
        T.Start()
    End Sub
    Private Sub TimerTicker(ByVal sender As Object, ByVal ev As EventArgs)
        Trace.WriteLine("here")
    End Sub
End Class
于 2011-01-05T20:16:23.313 に答える
0

特定の時間間隔で関数を実行することについて話しているのですか? その場合、Timerコントロールは機能します。Googleで簡単に検索すると、Timer に関する多数のチュートリアルが表示されます。

于 2011-01-05T20:15:52.640 に答える
0

これはどうでしょうか。Timer を使用し、MessageBox アラートを任意のメソッドに置き換えるだけです。

次の例では、5 秒ごとにアラームを鳴らす単純なインターバル タイマーを実装します。アラームが発生すると、アラームが開始された回数が MessageBox に表示され、タイマーの実行を継続するかどうかをユーザーに確認するメッセージが表示されます。

詳細については、こちらをご覧ください。

 Public Class Class1
>     Private Shared WithEvents myTimer As New System.Windows.Forms.Timer()
>     Private Shared alarmCounter As Integer = 1
>     Private Shared exitFlag As Boolean = False    

> 
>     ' This is the method to run when the timer is raised.
>     Private Shared Sub TimerEventProcessor(myObject As
> Object, _
>                                            ByVal myEventArgs As EventArgs) _
>                                        Handles myTimer.Tick
>         myTimer.Stop()
> 
>         ' Displays a message box asking whether to continue running the
> timer.
>         If MessageBox.Show("Continue running?", "Count is: " &
> alarmCounter, _
>                             MessageBoxButtons.YesNo) =
> DialogResult.Yes Then
>             ' Restarts the timer and increments the counter.
>             alarmCounter += 1
>             myTimer.Enabled = True
>         Else
>             ' Stops the timer.
>             exitFlag = True
>         End If
>     End Sub
> 
>     Public Shared Sub Main()
>         ' Adds the event and the event handler for the method that will
>         ' process the timer event to the timer.
> 
>         ' Sets the timer interval to 5 seconds.
>         myTimer.Interval = 5000
>         myTimer.Start()
> 
>         ' Runs the timer, and raises the event.
>         While exitFlag = False
>             ' Processes all the events in the queue.
>             Application.DoEvents()
>         End While
> 
>     End Sub    
> 
> End Class
于 2011-01-05T20:16:11.820 に答える