Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лек 013.doc
Скачиваний:
21
Добавлен:
07.02.2015
Размер:
137.73 Кб
Скачать

Public Property Get Interval() As Long

Interval = mlngInterval

End Property

'

Public Property Let Interval(ByVal NewInterval As Long)

' If the new value for Interval is the same as the old, there's no reason to do anything.

If NewInterval = mlngInterval Then Exit Property

' Save the new value.

mlngInterval = NewInterval

'

' If the XTimer is active, mlngTimerID is non-zero. in this case, the old system timer must be ended before a new one is started.

If mlngTimerID <> 0 Then

Call EndTimer(Me)

mlngTimerID = 0

End If

'

' If the new interval is zero, then the XTimer becomes inactive, regardless of the current value of Enabled. If the new interval is not zero, AND the Enabled property is True, then a new system timer is started, and its ID is stored in mlngTimerID.

If (NewInterval <> 0) And mblnEnabled Then

mlngTimerID = BeginTimer(Me, NewInterval)

End If

End Property

' RaiseTick method is called by the support module when the system timer event occurs for this XTimer object's system timer.

' Implementation detail: You might expect to declare this method Friend instead of Public, as there's no need for the client to call RaiseTick. However, it's critical that RaiseTick be declared Public, because the XTimer might be released while the Tick event is still being handled. An object will not terminate while one of its Public methods is on the stack, but it CAN terminate while one of its Friend methods is on the stack. If the object terminates before the Friend method returns (which could happen if the client executes a lot of code in the XTimer's Tick event), a GPF will result. (Note that this is a highly unusual scenario that depends on an external event; it does not occur in ordinary use of Friend functions.)

'

Public Sub RaiseTick()

RaiseEvent Tick

End Sub

Private Sub Class_Terminate()

' When the client releases its last reference to an XTimer object, it goes away -- but only if the XTimer's Enabled property is False, or its Interval property is True!

' This is because while the XTimer's system timer is running, the XTimerSupport module has to have a reference to the XTimer in order to raise its Tick event. Thus, failure of the client to disable XTimer objects before releasing them will LEAK system timers!

' These leaked system timers will not be recovered until the XTimers component shuts down -- that is, when the client using the DLL shuts down. The DLL will NOT unload when all XTimer objects are released, because references to public objects (in this case, those held by XTimerSupport) will prevent a DLL from unloading.

'So why bother to clean up the system timer in the Terminate event? Because when the DLL is getting shut down, all references to the XTimer object will be cleaned up and the XTimer will get its Terminate event. The system timer should be destroyed at this point.

On Error Resume Next

If mlngTimerID <> 0 Then KillTimer 0, mlngTimerID

' The following is what XTimer should do if it could somehow be released prior to DLL shutdown.

'If mlngTimerID <> 0 Then Call EndTimer(Me)

End Sub

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]