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
Imports System.IO

Public Class Logger

    ' Property variables
    Private _logFile As StreamWriter
    Private _startDateTime As Date
    Private _logFileName As String
    Private _fromPath As String
    Private _toPath As String
    Private _message As String

    ' Constants
    Private Const LOG_FILE As String = "Log.txt"
    Private Const ERR_MSG As String = "Error accessing file: "
    Friend Sub OpenLog()

        If _startDateTime = Nothing Then _startDateTime = Now
        If _logFileName = "" Then _logFileName = Format(_startDateTime, "yyMMdd-hhmmss") & "-" & LOG_FILE

        ' Create log file
        If Not File.Exists(_startDateTime & "-" & LOG_FILE) Then
            Using _logFile As StreamWriter = File.CreateText(_logFileName)
                _logFile.WriteLine("Logfile name is: " & _logFileName)
                _logFile.WriteLine("LOG FILE STARTED AT: " & _startDateTime.ToString)
                _logFile.WriteLine("============================================")
                _logFile.Write(_message)
                _logFile.WriteLine()
                _logFile.Close()
            End Using
        End If

    End Sub
    Friend Sub WriteLog()

        ' Create an instance of StreamWriter to write text to a file.
        Using _logFile As StreamWriter = File.AppendText(_logFileName)
            ' Add some text to the file.
            _logFile.WriteLine()
            _logFile.WriteLine("TIME OF LOG ENTRY: " & DateTime.Now)
            ' Arbitrary objects can also be written to the file.
            _logFile.WriteLine(_message)
            _logFile.Flush()
            _logFile.Close()
        End Using

    End Sub
    Public Property LogFileName() As String

        Get
            Return Format(StartDateTime, "yyMMdd-hhmmss") & "-" & LOG_FILE
        End Get
        Set(ByVal value As String)
            _logFileName = value
        End Set

    End Property
    Public Property StartDateTime() As Date

        Get
            Return _startDateTime
        End Get
        Set(ByVal value As Date)
            _startDateTime = value
        End Set

    End Property
    Public Property Message() As String

        Get
            Return _message
        End Get
        Set(ByVal value As String)
            _message = value
        End Set

    End Property
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.140921.1 | Last Updated 10 Jul 2008
Article Copyright 2006 by Taner Riffat
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid