|
-
Dec 11th, 2006, 02:10 PM
#1
Re: SOLVED: Is simulated multithreading the way to go (for what i need to do)?
Havent tested it but mostly referring to your gui if you have events that should fire like mouseovers which dont count towards the queue that the api looks at.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 11th, 2006, 03:46 PM
#2
Re: SOLVED: Is simulated multithreading the way to go (for what i need to do)?
I know it's marked as resolved, but just in case someone is interested in the multithreading option - a little demo program.
As to which is faster, MultiThreading or DoEvents, I'll leave others to argue. The obvious advantage of MultiThreading comes in when you have to perform other tasks within the same app. Make an executable of the code below and run it. Click on "Start MultiThread" and move the form around, scroll the textbox etc. The "AddTextMultiThread" function continues without even a pause. Click on "Stop MultiThread". Try the same with "Start/Stop DoEvents". Spot the difference.
'Original code at:- http://www.free2code.net/plugins/art...read.php?id=94
VB Code:
Option Explicit
'Form level code.
'MultiThread versus DoEvents.
'Add a textbox and 4 command buttons to a form.
Private Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, _
ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, _
ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, _
ByVal dwExitCode As Long) As Long
Private Sub Command1_Click()
id = CreateThread(ByVal 0&, ByVal 0&, AddressOf AddTextMultiThread, ByVal 0&, 0, id)
End Sub
Private Sub Command2_Click()
Call TerminateThread(id, ByVal 0&)
End Sub
Private Sub Command3_Click()
StopDo = True
AddTextDoEvents
End Sub
Private Sub Command4_Click()
StopDo = False
End Sub
Private Sub Form_Load()
Me.Height = 4545
Me.Width = 8925
Text1.Move 45, 45, 8700, 3525
Command1.Move 45, 3690, 1635, 375
Command1.Caption = "Start MultiThread"
Command2.Move 1845, 3690, 1635, 375
Command2.Caption = "Stop MultiThread"
Command3.Move 5310, 3690, 1635, 375
Command3.Caption = "Start DoEvents"
Command4.Move 7110, 3690, 1635, 375
Command4.Caption = "Stop DoEvents"
End Sub
VB Code:
'Module level code.
Option Explicit
Public id As Long
Public StopDo As Boolean
Public Function AddTextMultiThread()
Do
Form1.Text1.SelText = "Adding to Text1 - "
Loop
End Function
Public Function AddTextDoEvents()
StopDo = True
Do While StopDo = True
Form1.Text1.SelText = "Adding to Text1 - "
DoEvents
Loop
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|