-
December 10th, 2007, 10:42 PM
#1
How to fix window freeze while copying files...
I have a small program that copies files from a few locations from a hd to another folder.... sometimes these files combined are in excess of 50gb.. I have the progress bar written and it works, except the window freezes while its copying files and then it suddenly will move the progress bar and freeze again... eventually it completes the copy but you dont really see a nice transition on the progress bar....
Any help?
-
December 10th, 2007, 10:56 PM
#2
Re: How to fix window freeze while copying files...
is this in a program you have writen?
if so, can you post some code for us to see?
-
December 10th, 2007, 11:00 PM
#3
Re: How to fix window freeze while copying files...
Code:
Private dblTotal As Double
Private strDocuments, strDesktop, strSize, strOutlook, strOE, strFav As String
Private dblOutlookSize, dblDocumentsSize, dblOE, dblDesktop As Double
Private Sub cmdBackup_Click()
Dim fso As New FileSystemObject
strOutlook = Environ("USERPROFILE") & "\Local Settings\Application Data\Microsoft\Outlook"
strOE = Environ("USERPROFILE") & "\Local Settings\Application Data\Identities"
strDocuments = Environ("USERPROFILE") & "\My Documents"
strDesktop = Environ("USERPROFILE") & "\Desktop"
strFav = Environ("USERPROFILE") & "\Favorites"
If fso.FolderExists(strOutlook) = True Then
dblTotal = dblTotal + fso.GetFolder(strOutlook).Size
If Round((fso.GetFolder(strOutlook).Size / 1073741824), 2) > 0.99 Then
lblOutlookSize.Caption = Round((fso.GetFolder(strOutlook).Size / 1073741824), 2) & " GB"
ElseIf Round((fso.GetFolder(strOutlook).Size / 1048576), 2) > 0.99 Then
lblOutlookSize.Caption = Round((fso.GetFolder(strOutlook).Size / 1048576), 2) & " MB"
Else
lblOutlookSize.Caption = Round((fso.GetFolder(strOutlook).Size / 1024), 2) & " KB"
End If
Else
lblOutlookSize.Caption = "None"
End If
If fso.FolderExists(strOE) Then
dblTotal = dblTotal + fso.GetFolder(strOE).Size
If Round((fso.GetFolder(strOE).Size / 1073741824), 2) > 0.99 Then
lblOEsize.Caption = Round((fso.GetFolder(strOE).Size / 1073741824), 2) & " GB"
ElseIf (Round((fso.GetFolder(strOE).Size / 1048576), 2) > 0.99) Then
lblOEsize.Caption = Round((fso.GetFolder(strOE).Size / 1048576), 2) & " MB"
Else
lblOEsize.Caption = Round((fso.GetFolder(strOE).Size / 1024), 2) & " KB"
End If
Else
lblOEsize.Caption = "None"
End If
If fso.FolderExists(strDocuments) Then
dblTotal = dblTotal + fso.GetFolder(strDocuments).Size
If Round((fso.GetFolder(strDocuments).Size / 1073741824), 2) > 0.99 Then
lblDocsize.Caption = Round((fso.GetFolder(strDocuments).Size / 1073741824), 2) & " GB"
ElseIf (Round((fso.GetFolder(strDocuments).Size / 1048576), 2) > 0.99) Then
lblDocsize.Caption = Round((fso.GetFolder(strDocuments).Size / 1048576), 2) & " MB"
Else
lblDocsize.Caption = Round((fso.GetFolder(strDocuments).Size / 1024), 2) & " KB"
End If
Else
lblDocsize.Caption = "None"
End If
If fso.FolderExists(strDesktop) Then
dblTotal = dblTotal + fso.GetFolder(strDesktop).Size
If Round((fso.GetFolder(strDesktop).Size / 1073741824), 2) > 0.99 Then
lblDesktopSize.Caption = Round((fso.GetFolder(strDesktop).Size / 1073741824), 2) & " GB"
ElseIf (Round((fso.GetFolder(strDesktop).Size / 1048576), 2) > 0.99) Then
lblDesktopSize.Caption = Round((fso.GetFolder(strDesktop).Size / 1048576), 2) & " MB"
Else
lblDesktopSize.Caption = Round((fso.GetFolder(strDesktop).Size / 1024), 2) & " KB"
End If
Else
lblDesktopSize.Caption = "None"
End If
If fso.FolderExists(strFav) Then
dblTotal = dblTotal + fso.GetFolder(strFav).Size
If Round((fso.GetFolder(strFav).Size / 1073741824), 2) > 0.99 Then
lblFavsize.Caption = Round((fso.GetFolder(strFav).Size / 1073741824), 2) & " GB"
ElseIf (Round((fso.GetFolder(strFav).Size / 1048576), 2) > 0.99) Then
lblFavsize.Caption = Round((fso.GetFolder(strFav).Size / 1048576), 2) & " MB"
Else
lblFavsize.Caption = Round((fso.GetFolder(strFav).Size / 1024), 2) & " KB"
End If
Else
lblFavsize.Caption = "None"
End If
lblTotalSize.Caption = Round((dblTotal / 1073741824), 2) & " GB"
userInput = txtLocation.Text
If Not fso.FolderExists(userInput) Then
fso.CreateFolder userInput
End If
ProgressBar1.Min = 0
ProgressBar1.Max = 100
ProgressBar1.Value = 0
lblPercent.Caption = Int(ProgressBar1.Value * 100 / ProgressBar1.Max)
lblPercent.Refresh
If fso.FolderExists(strOutlook) Then
fso.CopyFolder strOutlook, userInput & "\Outlook"
DoEvents
ProgressBar1.Value = (ProgressBar1.Value + CInt((fso.GetFolder(strOutlook).Size / dblTotal) * 100))
End If
If fso.FolderExists(strOE) Then
fso.CopyFolder strOE, userInput & "\Outlook Express"
DoEvents
ProgressBar1.Value = (ProgressBar1.Value + CInt((fso.GetFolder(strOE).Size / dblTotal) * 100))
End If
If fso.FolderExists(strDocuments) Then
fso.CopyFolder strDocuments, userInput & "\My Documents"
DoEvents
ProgressBar1.Value = (ProgressBar1.Value + CInt((fso.GetFolder(strDocuments).Size / dblTotal) * 100))
End If
If fso.FolderExists(strDesktop) Then
fso.CopyFolder strDesktop, userInput & "\Desktop"
DoEvents
ProgressBar1.Value = ProgressBar1.Value + CInt((fso.GetFolder(strDesktop).Size / dblTotal) * 100)
End If
If fso.FolderExists(strFav) Then
fso.CopyFolder strFav, userInput & "\Favorites"
DoEvents
ProgressBar1.Value = (ProgressBar1.Value + CInt((fso.GetFolder(strFav).Size / dblTotal) * 100))
End If
lblPercent.Caption = Int(ProgressBar1.Value * 100 / ProgressBar1.Max)
lblPercent.Refresh
End Sub
I see already that i could just place the lblPrecent modifier/refresher at the end of each copy...
I would try to fraise this in a loop but im not sure how i would do it.... Its been a while since i wrote any vb6 code.... Im trying ot learn vb.net so please forgive me if its obvious...
But even if i did place it in a loop would it still freeze the window?
-
December 10th, 2007, 11:13 PM
#4
Re: How to fix window freeze while copying files...
CopyFolder doesn't indicate any progress. Your code will take forever to run.
You should write this in .Net, using a couple of subthreads being controlled by a main thread.
-
December 10th, 2007, 11:16 PM
#5
Re: How to fix window freeze while copying files...
Do you know any good compilers? I have little experience with .net so im looking for one that can help me autocomplete....
-
December 10th, 2007, 11:19 PM
#6
Re: How to fix window freeze while copying files...
Download Visual Studio 2005 Express and visit the VB.Net forum.
VS 2008 is also available, but might be in beta still.
-
December 10th, 2007, 11:31 PM
#7
Re: How to fix window freeze while copying files...
Wow VB 2008 Express looks awesome... downloading it now.... thanks for the info... ill convert my backup program to a vb.net application...
Ill let you know how it turns out...
Thanks,
Heath
-
December 11th, 2007, 02:25 AM
#8
Re: How to fix window freeze while copying files...
In VB 2005, I would have used a single statement My.Computer.FileSystem.CopyFile or My.Computer.FileSystem.CopyDirectory.
It should be present in VB 2008 also.
-
December 11th, 2007, 04:15 AM
#9
Re: How to fix window freeze while copying files...
Originally Posted by Shuja Ali
It should be present in VB 2008 also.
yes it is
http://msdn2.microsoft.com/en-us/lib...5e(VS.90).aspx
-
December 13th, 2007, 01:14 AM
#10
Re: How to fix window freeze while copying files...
Is it possible to use threads in VB?
-
December 13th, 2007, 01:49 AM
#11
Re: How to fix window freeze while copying files...
Not real easily in VB6, but VB.Net is made for multi-threading.
-
December 13th, 2007, 01:52 AM
#12
Re: How to fix window freeze while copying files...
Originally Posted by s00263668
Is it possible to use threads in VB?
This is not related to the topic discussed in this thread. Ideally you should have searched the forum and would have gotten your answer by now or you could have created a new thread.
This might give you some insight why it is not easy to implement multi-threading and what are the workarounds.
-
December 13th, 2007, 08:37 AM
#13
Re: How to fix window freeze while copying files...
-
December 14th, 2007, 07:14 PM
#14
Re: How to fix window freeze while copying files...
Just to let you know, it's possible to copy a file in VB6 without hanging the window, there is an API called CopyFileEx that is pretty easy to use, there is an example here:
http://www.mentalis.org/apilist/CopyFileEx.shtml
JeffB
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
|