- •Лекция 13
- •XTimers.Vbp 5
- •Обзор задачи Coffee Sample Application
- •XTimers.Vbp
- •XTimerSupport.Bas
- •Private Type xtimerinfo ' Hungarian xti
- •Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal lngSysTime As Long)
- •If maxti(intCt).BlnReentered Then Exit Sub
- •Public Sub EndTimer(ByVal xt As xTimer)
- •Public Sub Scrub()
- •Public Property Get Interval() As Long
- •Public Property Let Interval(ByVal NewInterval As Long)
- •Public Sub RaiseTick()
- •Private Sub Class_Terminate()
- •MtCoffee.Vbp modMt.Bas Option Explicit
- •Public glngGlobalData As Long
- •Coffee.Bas
- •Option Explicit
- •Private Declare Function timeGetTime Lib "winmm.Dll" () As Long
- •Private mlngIterations As Long
- •Public Property Get NumberOnThread() As Long
- •Public Sub StartLongTask(ByVal Iterations As Long)
- •Public Function GetCoffeeOnSameThread() As Coffee
- •Public Function GetCoffeeOnNewThread() As Coffee
- •If blnCancel Then
- •Coffee.Cls Option Explicit Private Declare Function timeGetTime Lib "winmm.Dll" () As Long
- •Private mlngIterations As Long
- •Public Property Get NumberOnThread() As Long
- •Public Sub StartLongTask(ByVal Iterations As Long)
- •Public Function GetCoffeeOnSameThread() As Coffee
- •Public Function GetCoffeeOnNewThread() As Coffee
- •If blnCancel Then
- •Public Property Get CoffeeMonitor() As CoffeeMonitor
- •If gCoffeeMonitor Is Nothing Then
- •CoffeeMonitor.Cls Option Explicit
- •Private WithEvents mwXTimer As xTimer
- •Event CoffeeReady() Private Sub Class_Initialize()
- •Private Sub Class_Terminate()
- •Private Sub mwXTimer_Tick()
- •Connector2.Cls Option Explicit
- •Public Property Get CoffeeMonitor2() As CoffeeMonitor2
- •CoffeeMonitor2 Option Explicit
- •Private maicnClients() As iCoffeeNotify
- •Public Sub TellMeReady(ByVal icn As iCoffeeNotify)
- •Public Sub CeaseCallBacks(ByVal icn As iCoffeeNotify)
- •Private Sub mwXTimer_Tick()
- •ICoffeeNotify.Cls
- •Public ThreadId As Long
- •Private Sub mwCoffee_Progress(ByVal PercentDone As Single, Cancel As Boolean)
- •Private Sub cmdCallBacks_Click()
- •Private Sub cmdMt_Click()
- •Private Sub Form_Unload(Cancel As Integer)
- •Private Sub mwcmnEvents_CoffeeReady()
- •FrmThread.Frm
- •Private Sub cmdCancel_Click()
- •Private Sub cmdShortOnly_Click()
- •Private Sub cmdShortLong_Click()
- •Private Sub cmdNLong_Click()
- •Private Sub cmdXThread_Click()
- •Private Sub cmdIDs_Click()
- •Private Sub tmrShort_Timer()
Private Sub tmrShort_Timer()
Static intCt As Integer
Static strWaitingFor As String
Dim cft As CoffeeTracker
' If strWaitingFor contains a key, then the Coffee object is (or was) performing
' a task, and the static string variable contains the key of the CoffeeTracker that's watching it.
If strWaitingFor <> "" Then
On Error Resume Next
'
' If the CoffeeTracker we're waiting for has dropped out of the collection, then an error will
' occur -- meaning it's time to start another one.
Set cft = CoffeeTrackers(strWaitingFor)
If Err.Number = 0 Then Exit Sub
Else
' If the static string variable is empty, then the previous series of short tasks is complete. A
' new series is beginning, so reset the static counter (intCt).
intCt = 0
End If
If Not CancelAll Then
intCt = intCt + 1
'
' Create a CoffeeTracker to wait for the request to finish.
Set cft = NewTracker(macfe(10).ThreadID, SHORTTASKSIZE)
'
' Give the CoffeeTracker its Coffee object to watch.
Set cft.Coffee = macfe(10)
'
' Begin the task.
Call macfe(10).StartLongTask(SHORTTASKSIZE)
'
' Prepare to wait for the CoffeeTracker.
strWaitingFor = cft.ID
End If
'
' Check to see if we've completed the series of short tasks, or if we've been stopped by the Cancel button:
If (intCt >= mintHowManyShort) Or CancelAll Then
intCt = 0
tmrShort.Enabled = False
strWaitingFor = ""
End If
End Sub