|
-
Apr 16th, 2011, 09:03 PM
#7
Thread Starter
Member
Re: Program Keeps Hanging
Hey, bergerkiller! Thanks a lot for the help! I've managed to get my program to multi-thread, finally! It turns out that I wasn't multi-threading the main Sub that triggered the CopyAllFiles Sub. Now I have three threads: One for copying, one for updating the text on the screen, and one for showing forms (otherwise I'd get an error that the main thread is supposed to handle showing them). This works very, very well, and the program no longer hangs, even when copying over 9 GB of data! I just have to fix up some of the visual aspects of it because some forms don't pop up as they're supposed to.
Also, I'd like to mention that I used DirectoryInfo and FileInfo, and they do work with a thread that isn't the main thread. Below is an example of what I did for the text updating thread:
Code:
Public TextThread As Threading.Thread
Public Sub TextUpdate()
TextThread = New Threading.Thread(AddressOf UpdateText)
TextThread.Start()
End Sub
Public Sub UpdateText()
frmDisplay.txtDisplay.Text = DisplayText
frmDisplay.txtDisplay.SelectionStart = frmDisplay.txtDisplay.Text.Length
frmDisplay.txtDisplay.ScrollToCaret()
TextThread.Abort()
End Sub
I also decided to put most of my Subs in a separate Module as opposed to on the main form itself. This allowed me to utilize global variables and make my life easier. 
Thanks again!
Tags for this Thread
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
|