Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » VB.NET » Utilities » Downloads
 
Add your own
alternative version
Go to top

Multithreading Backup Utility

, 10 Jul 2008
Multithreading is something we will all have to deal with sooner or later. This relatively simple application shows you how to use two threads to copy files. It is also a very handy Windows backup utility with a mirror feature, a batch mode feature, a log file feature and a help button!
Backup.zip
Backup
Backup.ico
Backup.vbproj.user
bin
Debug
Release
Backup.vshost.exe
Backup.vshost.exe.manifest
Help.pdf
Icon1.ico
Icons
error.ico
INFO.ICO
none.ico
question.ico
Thumbs.db
warning.ico
License.rtf
My Project
app.manifest
Application.myapp
Settings.settings
Resources
coder.bmp
coder.jpg
error.ico
Icon1.bmp
Icon1.ico
Icon2.ico
Image1.ico
INFO.ICO
none.ico
question.ico
small.ico
small1.ico
small11.ico
Thumbs.db
warning.ico
Thumbs.db
VSProject_genericproject.ico
VTune
Backup.vpj
BackupSetup.zip
setup.exe
Setup.msi
Public Class AppManager

    <STAThread()> _
    Shared Sub Main()
        ' Set form style defaults
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)

        ' Test for command line parameters.
        If Environment.GetCommandLineArgs.Length > 1 Then
            ' If in batch mode just instantiate the FileCopy class as no form is needed.
            ' Also don't declare this class "withevents" as the events only report status
            ' data (like the number of files copied so far).
            Dim BatchCopy As New FileCopy

            ' Setup the copy parameters for the BatchCopy instance from command line arguments
            Dim Argument As String
            Dim Index As Integer = 0
            For Each Argument In Environment.GetCommandLineArgs
                Select Case Index
                    Case 0
                        ' The first argument is the app file/path so do nothing
                    Case 1
                        BatchCopy.FromPath = Environment.GetCommandLineArgs(1).ToString
                    Case 2
                        BatchCopy.ToPath = Environment.GetCommandLineArgs(2).ToString
                    Case 3
                        If Environment.GetCommandLineArgs(3).ToString.ToUpper = "TRUE" Then
                            BatchCopy.MirrorCopy = True
                        Else
                            BatchCopy.MirrorCopy = False
                        End If
                    Case 4
                        If Environment.GetCommandLineArgs(4).ToString.ToUpper = "TRUE" Then
                            BatchCopy.QuietLog = True
                        Else
                            BatchCopy.QuietLog = False
                        End If
                    Case Else
                        ' Ignore any remaining arguments as something is wrong. The BatchCopy class
                        ' will log any errors in the log file.
                End Select
                Index += 1
            Next

            ' Start the multithreaded copy 
            BatchCopy.InitialMessage = "*** MODE IS BATCH ***"
            If BatchCopy.MirrorCopy Then
                BatchCopy.InitialMessage = "*** MODE IS BATCH - MIRROR COPY IS SET ***"
            End If
            If BatchCopy.QuietLog Then
                BatchCopy.InitialMessage += vbCrLf & "Logging is quiet - not verbose."
            Else
                BatchCopy.InitialMessage += vbCrLf & "Logging is not quiet - its verbose."
            End If
            BatchCopy.BatchCopy = True
            BatchCopy.StartCopy()

            BatchCopy.WaitForThreads()
        Else
            ' Forms mode so open the Backup form. The Backup from will instantiate the FileCopy class
            ' when the "Go" button is pressed.
            Dim BackupForm As Backup
            BackupForm = New Backup()
            Application.Run(BackupForm)
        End If

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Taner Riffat
Nice people only.
Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 10 Jul 2008
Article Copyright 2006 by Taner Riffat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid