Visual Basic .NET: расписание - PullRequest
       10

Visual Basic .NET: расписание

1 голос
/ 05 января 2011

Можно ли как-нибудь проверить в моей форме Visual Basic .NET выполнение функции каждые X интервалов?

Ответы [ 3 ]

4 голосов
/ 05 января 2011

Проверьте Таймер класс.

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
0 голосов
/ 05 января 2011

Как насчет этого: использовать таймер, и просто заменить любой метод, который вы хотите, для оповещения MessageBox.

В следующем примере реализован простой интервальный таймер, который срабатывает каждые пять секунд. При возникновении тревоги 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
0 голосов
/ 05 января 2011

Вы говорите о запуске функции через определенный промежуток времени?Если это так, то будет работать Timer .Быстрый поиск в Google даст вам несколько учебных пособий по таймеру.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...