View Single Post
Old Jul 4th, 2007, 3:30 PM   #1
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
Preventing Timeout Message During Long Processes

So currently I am working on a program to backup files. What it does is search through each directory recursively like so:
vbnet Syntax (Toggle Plain Text)
  1. Public Sub BackUp(ByVal root As String)
  2. Dim FoundFile, FoundDirectory As String
  3. 'Loop thru each of the files in this directory
  4. For Each FoundFile In My.Computer.FileSystem.GetFiles(root)
  5. If (IO.File.GetAttributes(FoundFile) = IO.FileAttributes.Archive) Or RootCreated Then
  6. ListBox1.Items.Add(FoundFile)
  7. ListBox1.Update()
  8. Dim FileName As String
  9. FileName = RemoveSource(FoundFile, Source)
  10. Try
  11. IO.File.Copy(FoundFile, Destination & FileName)
  12. Catch ex As Exception
  13. Dim DestFile As String = Destination & FileName
  14. Dim DestFileArr() As String = DestFile.Split("\")
  15. Dim l As Integer
  16. Dim folder As String
  17. folder = DestFileArr(0)
  18. For l = 1 To DestFileArr.GetUpperBound(0) - 1
  19. folder = folder & "\" & DestFileArr(l)
  20. If Not IO.Directory.Exists(folder) Then
  21. IO.Directory.CreateDirectory(folder)
  22. End If
  23. Next
  24. Try
  25. IO.File.Copy(FoundFile, Destination & FileName)
  26. Catch ex1 As Exception
  27. MsgBox("Error:" & Chr(13) & ex1.Message & Chr(13) & " No Folder for the file to be placed in")
  28. End Try
  29. End Try
  30. ' IO.File.SetAttributes(FoundFile, IO.FileAttributes.Normal)
  31. IO.File.SetCreationTime(Destination & FileName, IO.File.GetCreationTime(FoundFile))
  32. IO.File.SetLastAccessTime(Destination & FileName, IO.File.GetLastAccessTime(FoundFile))
  33. IO.File.SetAccessControl(Destination & FileName, IO.File.GetAccessControl(FoundFile))
  34. IO.File.SetLastWriteTime(Destination & FileName, IO.File.GetLastWriteTime(FoundFile))
  35. End If
  36. Next
  37. 'Loop thru each directory in this directory
  38. For Each FoundDirectory In My.Computer.FileSystem.GetDirectories(root)
  39. 'Give the user feedback about progress
  40. 'LabelSearch.Text = "Scanning: " & FoundDirectory
  41. 'LabelSearch.Update()
  42.  
  43. 'Recursively call this very same sub procedure!
  44. BackUp(FoundDirectory)
  45. Next
  46. End Sub
I have a problem after I hit about the 100th file, it "dies" and the compiler is like it's taking to long. It then asks me if I want to continue and I say yes. How do I stop that? I've tried GC.KeepAlive(me), for each file but that didn't seem to work. This is going to be used for directories that could possibly have over 100k files and I don't want to have to sit and hit yes every so many times.
PhilBon is offline   Reply With Quote