VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ClassMT3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Guide to the Perplexed - Multithreading DLL example
' Copyright (c) 1997 by Desaware Inc. All Rights Reserved
'
Option Explicit

Private CurrentMessage$
Private InProgress As Boolean
Private DebugMon As DebugMonitor.Trace

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

' 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

' We don't actually do anything, just marshal the string
Public Sub ShortOp(ByVal msg$)

End Sub

Public Sub ShowTID(ByVal msg$)
    DebugMon.Add msg & " TID: " & GetCurrentThreadId()
End Sub

Private Sub Class_Initialize()
    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: " & GetCurrentThreadId()
    DebugMon.Add msg
End Sub
