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

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


' 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 1000
        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
' Call a long op in a non multithreaded DLL
Public Sub CallDllNoMTLong(ByVal msg$)
    Dim dllNonMT As New gtpMT3.ClassMT3
    dllNonMT.LongOp msg
End Sub

' Call a long op in a non multithreaded DLL
Public Sub CallDllMTLong(ByVal msg$)
    Dim dllMT As New gtpMT4.ClassMT4
    dllMT.LongOp msg
End Sub


' Call a non multithreading DLL
Public Sub CallDllNoMT(ByVal msg$)
    Dim Elapsed As New clsElapsedTime
    Dim dllNonMT As New gtpMT3.ClassMT3
    Dim x&
    CurrentMessage = msg
    dllNonMT.ShowTID "CallDllNoMT in TID: " & App.ThreadID & " on DLL object"
    Elapsed.StartTheClock
    For x = 1 To 4000
        dllNonMT.ShortOp "This string must be marshaled"
    Next x
    Elapsed.StopTheClock
    Report Elapsed
End Sub

' Call a multithreading DLL
Public Sub CallDllMT(ByVal msg$)
    Dim Elapsed As New clsElapsedTime
    Dim x&
    Dim dllMT As New gtpMT4.ClassMT4
    CurrentMessage = msg
    dllMT.ShowTID "CallDllMT in TID: " & App.ThreadID & " on DLL object"
    Elapsed.StartTheClock
    For x = 1 To 400000  ' Note: factor of 10 slower
        dllMT.ShortOp "This string must be marshaled"
    Next x
    Elapsed.StopTheClock
    Report Elapsed
End Sub
