Program freezes while copying files
Program freezes while copying files
Program freezes while copying files
Program freezes while copying files
Program freezes while copying files
Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files
Program freezes while copying files Program freezes while copying files
Program freezes while copying files
Go Back  Xtreme Visual Basic Talk > > > Program freezes while copying files


Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2015, 06:30 AM
james7285 james7285 is offline
Newcomer
 
Join Date: Jul 2003
Posts: 9
Default Program freezes while copying files


I am a bit of a novice with vb.net so bare with me!

I have a program that when you click the "update" button it copies over all folders and files in a specific directory onto a memory stick.

The code itself works fine, the issue I'm having is that I would like to have a list box which updates as each file is added. I was also thinking about adding a progress bar at some point as well.

This is the code:

Code:
Dim oFiles() As IO.FileInfo
        Dim oFile As IO.FileInfo
        Dim oDirectory As New IO.DirectoryInfo(sOriginal)
        IO.Directory.CreateDirectory(sDestination)
        Try
            oFiles = oDirectory.GetFiles()
        Catch ex As UnauthorizedAccessException
            Exit Sub
        End Try
        For Each oFile In oFiles
            IO.File.Copy(oFile.FullName, sDestination & "\" & oFile.FullName.Substring(sOriginal.Length))
            lstMain.Items.Add(oFile.FullName)
        Next
        Try
            For Each oEntry As IO.DirectoryInfo In oDirectory.GetDirectories
                CopyDirectory(oEntry.FullName, sDestination & "\" & oEntry.FullName.Substring(sOriginal.Length))
            Next
        Catch ex As Exception
        End Try
        cmdUpdate.Enabled = True
When you run it the program freezes and it isn't until the end that it becomes responsive again and the listbox suddenly becomes populated.

I know there is something about threading or background workers which is what I would assume would fix my problem, but I'm a bit confused with it all and could do with some help.

Thanks

James
Reply With Quote
  #2  
Old 04-20-2015, 08:50 AM
Gruff's Avatar
GruffProgram freezes while copying files Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Not to avoid the question, but have you thought about just using a batch file and driving it from a desktop icon?

Not all solutions are programming ones.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 04-20-2015, 08:52 AM
james7285 james7285 is offline
Newcomer
 
Join Date: Jul 2003
Posts: 9
Default

Thanks for the reply.

The source folders can change from time to time so I wrote the app with the intention of being able to choose where you want the files to come from.

It also does a couple of other bits not related to this current task.
Reply With Quote
  #4  
Old 04-20-2015, 03:37 PM
Gruff's Avatar
GruffProgram freezes while copying files Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Okay,

here is an example that shows estimated time till completion
It uses the Microsoft.VisualBasic.FileIO namespace

https://msdn.microsoft.com/en-us/library/cc165446.aspx

It is a C# example but short so you should easily convert it to VB.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 04-20-2015 at 04:02 PM.
Reply With Quote
  #5  
Old 04-21-2015, 03:32 AM
james7285 james7285 is offline
Newcomer
 
Join Date: Jul 2003
Posts: 9
Default

Thanks for the post. I have implemented that solution and it works fine.

My original intention was to have each file added to the listbox one by one as it copies over, but I think that sounds like it's going to be a headache to do so I will stick with this solution.

Thanks once again.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Program freezes while copying files
Program freezes while copying files
Program freezes while copying files Program freezes while copying files
Program freezes while copying files
Program freezes while copying files
Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files Program freezes while copying files
Program freezes while copying files
Program freezes while copying files
 
Program freezes while copying files
Program freezes while copying files
 
-->