I'm currently reviewing a bit of an older console application which performs certain tasks depending on the command line argument that is given. These tasks are called through Windows Task Scheduler.However reflecting on this I find the code to be ugly and I'm wondering if there is a better way to do something like this.Public Shared Sub ParseTasks(ByVal CmdArgs() As String)        ConvertAndWriteArgs(CmdArgs)        Try            Select Case CmdArgs(0)                Case SCRIPTS                    'SCRIPTS has 1 input parameter: ScheduleType                    If CmdArgs.Length < 2 Then                       ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)                    Else                        Scripts(sheduleType:=CmdArgs(1).ToString)                    End If            Case CHECKTRANSFERREPLICATION                CheckTransferReplication()            Case CREATESYBASEBACKUP11                CreateSybaseBackup11()            Case SQLCOMMAND                SqlCommand()            Case REPLICATION_IN                'Replication In has 1 input parameter: Range                If CmdArgs.Length < 2 Then                    ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)                Else                    ReplicationImport(range:=CmdArgs(1).ToString())                End If            Case REPLICATION_OUT                'Replication Out has 1 input parameter: Range                If CmdArgs.Length < 2 Then                    ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)                Else                    ReplicationExport(Range:=CmdArgs(1).ToString)                End If            Case REEXPORTFILE                'Re export file Out has 1 input parameter: FileName                If CmdArgs.Length < 2 Then                    ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)                Else                    ReExportFile(fileName:=CmdArgs(1).ToString)                End If            Case UPGRADE                'Upgrade has 1 input parameter: ScriptFolder                If CmdArgs.Length < 2 Then                    ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)                Else                    Upgrade(scriptFolder:=CmdArgs(1).ToString)                End If            Case DUPLICATES                Duplicates()            Case Else                ExceptionLogger.LogExceptionEvent(Invalid Arguments, Severity.Error)            End Select        Catch ex As Exception           ExceptionLogger.LogExceptionEvent(ex, Severity.Error)        End Try    End Sub#Region Task functions    Private Shared Sub AutoScripts(ByVal sheduleType As String)        Trace.TraceInformation(Creating AutoScripts Task.)        Dim task = New AutoScripts        With task            .ScheduleType = ConvertScheduleType(sheduleType)        End With        Trace.TraceInformation(Schedule Type:  & task.ScheduleType.ToString)        task.Start()    End Sub    Private Shared Sub CheckTransferReplication()        Trace.TraceInformation(Creating CheckTransferReplication Task.)        Dim task = New CheckTransferReplication        task.Start()    End Sub    Private Shared Sub CreateSybaseBackup11()        Trace.TraceInformation(Creating CreateSybaseBackup11 Task.)        Dim task = New CreateSybaseBackup        task.Start()    End Sub    Private Shared Sub SqlCommand()        Trace.TraceInformation(Creating SqlCommand Task.)        Dim task = New Business.Task.ExecuteSqlCommand        task.Start()    End Sub    Private Shared Sub ReExportFile(ByVal fileName As String)        Trace.TraceInformation(Creating ReExportFile Task.)        Dim task = New ReExportFile        With task            .FileName = fileName        End With        task.Start()    End Sub    Private Shared Sub Upgrade(ByVal scriptFolder As String)        Trace.TraceInformation(Creating UpgradeSybaseDatabases Task.)        Dim task = New UpgradeSybaseDatabases        With task            .ScriptFolder = scriptFolder        End With        task.Start()    End Sub#Region Replication    Private Shared Sub ReplicationImport(ByVal range As String)        Trace.TraceInformation(Creating ReplicationImport Task.)        Dim task = New ExecuteReplication        task.ReplicationType = Business.ReplicationType.Import        If range.Equals(001, StringComparison.OrdinalIgnoreCase) Then            task.ReplicationGroup = Business.ReplicationGroup.HeadOffice            task.Start()            Try                EdimarObjectDAO.ProcessRefErrors()            Catch ex As Exception                ExceptionLogger.LogExceptionEvent(ex, ProblemSeverity.Error)            End Try            Dim sqlCommandTask = New ExecuteSqlCommand            SqlCommandTask.Start()        Else            task.ReplicationGroup = Business.ReplicationGroup.Sattelite            task.ReplicationSatteliteRange = range            task.Start()        End If    End Sub    Private Shared Sub ReplicationExport(ByVal range As String)        Trace.TraceInformation(Creating ReplicationExport Task.)        Dim task = New ExecuteReplication        task.ReplicationType = Business.ReplicationType.Export        If Range.Equals(001, StringComparison.OrdinalIgnoreCase) Then            task.ReplicationGroup = Business.ReplicationGroup.HeadOffice            task.Start()        Else            task.ReplicationGroup = Business.ReplicationGroup.Sattelite            task.ReplicationSatteliteRange = Range            task.Start()        End If    End Sub    Private Shared Sub ProcessLogFiles()        Trace.TraceInformation(Processing Replication Logfiles.)        Dim task = New ProcessLogFiles        task.Start()    End Sub#End Region#End Region#Region Helper Functions    Private Shared Sub ConvertAndWriteArgs(ByVal CmdArgs() As String)        Dim strArgs = String.Empty        For Each arg In CmdArgs            If strArgs = String.Empty Then                strArgs = arg            Else                strArgs +=   & arg            End If        Next        Trace.TraceInformation(Arguments:  & strArgs)    End Sub    Private Shared Function ConvertScheduleType(ByVal scheduleType As String) As Business.ScheduleType        Dim schedule As Business.ScheduleType        Select Case ScheduleType            Case M                schedule = Business.ScheduleType.Monthly            Case W                schedule = Business.ScheduleType.Weekly            Case W2                schedule = Business.ScheduleType.Weekly2            Case D                schedule = Business.ScheduleType.Daily            Case D2                schedule = Business.ScheduleType.Daily2            Case Else                ExceptionLogger.LogExceptionEvent(Invalid Arguments, ProblemSeverity.Error)        End Select        Return schedule    End Function#End Region
Performing actions based on command line arguments
design patterns;vb.net;scheduled tasks