Program Hangs on Client Computers
Hello, everyone! I've created a multithreaded application that copies data from one directory to another, and I'm having trouble getting it to work properly on clients' computers. All computers running the software have Windows 7 and the .NET Framework 4.0 Client Profile installed, which is what I've compiled the program for. I have two threads: one does the actual copying, and the other updates the UI on the program. Whenever I run the program on my computer, even if I'm copying 45 GB, for example, it runs fine. However, if I run it on another computer, it will sometimes freeze the entire computer, so then I have to manually shut the computer down in order to use it again. I have been trying to find out why this occurs, but I cannot. Does anyone think he/she can provide me with some ideas as to why this happens and how I can prevent it from occurring? Thanks in advance!
Re: Program Hangs on Client Computers
You should start by giving us a clearer explanation of exactly what the application is doing.
Re: Program Hangs on Client Computers
Quote:
Originally Posted by
jmcilhinney
You should start by giving us a clearer explanation of exactly what the application is doing.
Okay, sorry about that. So the application takes clients' data, which was uploaded to a server, and copies it to the respective directories on the local hard drive. For example, on the server, it will have a folder for a user called "My Documents." The program copies the contents of the My Documents folder and puts it into Windows 7's Documents folder. The copying Sub is as follows:
Code:
Public Sub CopyAllFiles(ByVal Source As String, ByVal Destination As String)
Dim Text As String = vbNullString, FinalPath As String
Dim Dir As New DirectoryInfo(Source), DestDir As New DirectoryInfo(Destination)
Dim DirectoryList() As DirectoryInfo
Dim FileList() As FileInfo
If Not DestDir.Exists() Then
DestDir.Create()
End If
FileList = Dir.GetFiles()
For Each f As FileInfo In FileList
FinalPath = Path.Combine(Destination, f.Name)
If ReplaceSetting <> 2 Then
If File.Exists(FinalPath) Then
OverwriteMsg = "The file " & Destination & "\" & f.Name & " already exists. Would you like to replace it?"
context.Send(AddressOf ShowForm, frmOverwrite)
Else
ReplaceSetting = 1
End If
End If
If ReplaceSetting = 1 Or ReplaceSetting = 2 Then
DisplayText = DisplayText & vbNewLine & "Copying to " & FinalPath & "..."
context.Send(AddressOf UpdateText, Nothing)
Try
f.CopyTo(FinalPath, True)
CurrentSize = CurrentSize + f.Length
context.Send(AddressOf UpdateProgress, Nothing)
Catch
DisplayText = DisplayText & vbNewLine & "Error copying " & FinalPath & "..."
context.Send(AddressOf UpdateText, Nothing)
End Try
End If
Next
DirectoryList = Dir.GetDirectories()
For Each d As DirectoryInfo In DirectoryList
FinalPath = Path.Combine(Destination, d.Name)
CopyAllFiles(d.FullName, FinalPath)
Next
End Sub
Here are some public declarations that exist in this Sub:
Code:
Public context As Threading.SynchronizationContext = Threading.SynchronizationContext.Current ' Updates the GUI
Public ReplaceSetting As Integer = -1 ' Indicates whether the user wants to replace the file if it already exists; -1 = Nothing; 0 = No; 1 = Yes; 2 = Replace All
Public CurrentSize As Double ' Keeps track of how much data was copied over so far
I hope that's enough information!
Re: Program Hangs on Client Computers
Could it be that the files you are copying on the other computer are open and locked by another process? That could cause an exception in your code which if you aren't handling gracefully could cause the thread to lock up.
VB.NET Help
Re: Program Hangs on Client Computers
Quote:
Originally Posted by
mjwest10
Could it be that the files you are copying on the other computer are open and locked by another process? That could cause an exception in your code which if you aren't handling gracefully could cause the thread to lock up.
VB.NET Help
Well, I do have a Try and Catch statement in there for when the program copies the file over. If there's an error, it'll just display "Error copying [filepath]" and won't copy the file over. Also, I'm copying the files over to Windows 7 after reformatting the hard drive, so I don't think that there would be any processes using the files that my program is trying to copy over.