VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ClassMT5"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private CurrentMessage$
Private InProgress As Boolean
Private debugmon As DebugMonitor.Trace
Private CallerToNotify As Object

' Performs a long operation
' Measures the time to do it and
' reports it
Public Sub LongOp(msg$)
    Dim ctr&
    Dim x&
    Dim s$
    Dim Elapsed As New clsElapsedTime
    CurrentMessage = msg
    ' A nice long operation that can't
    ' be optimized away
    Elapsed.StartTheClock
    
    For ctr = 1 To 5000
        For x = 1 To 255
            s$ = Chr$(x)
        Next x
    Next ctr
    Elapsed.StopTheClock
    Report Elapsed
End Sub


Private Sub Class_Initialize()
    ' Preload objects so they aren't included in elapsed time
    Set debugmon = New DebugMonitor.Trace
End Sub

Private Sub Class_Terminate()
    Set debugmon = Nothing
End Sub

' Report the current message and elapsed time
Friend Sub Report(elp As clsElapsedTime)
    Dim msg$
    msg$ = CurrentMessage$ & " Time: " & elp.Elapsed & " TID: " & App.ThreadID
    debugmon.Add msg
End Sub

' Get the thread ID of an object
Public Function ObjectThreadId() As Long
    ObjectThreadId = App.ThreadID
End Function

' Tries to start a background operation using a timer
Public Sub StartBackground1(ToNotify As Object)
    Set CallerToNotify = ToNotify
    debugmon.Add "Starting timer from TID: " & App.ThreadID
    StartTimer Me
End Sub

' Background operation is starting
Friend Sub TimerExpired()
    debugmon.Add "Starting Background Op in TID: " & App.ThreadID
    LongOp "Background Op Done "
    ' OLE callback to calling object
    If CallerToNotify Is Nothing Then Exit Sub
    CallerToNotify.BackgroundNotify
    Set CallerToNotify = Nothing
End Sub
