In Theory is this the correct use of a singleton object? I only want them to be able to run this process once(of course by closeing and restarting the application stops that functionality).
Is this setup properly?
Public Class OracleSnapshot
Private Shared m_instance As OracleSnapshot
Private Sub New()
Try
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Enviro nment.NewLine)
m.Append(ex.ToS tring)
MessageBox.Show (m.ToString, "Error Creating Snapshot")
End Try
End Sub
Public Shared Function Activate() As OracleSnapshot
If m_instance Is Nothing Then
m_instance = New OracleSnapshot
End If
Return m_instance
End Function
Private Shared Sub runSnapshot()
Dim config As New Configuration.A ppSettingsReade r
Dim sqlDatabase, sqlServer As String
sqlDatabase = config.GetValue ("databasename" , GetType(String) )
sqlServer = config.GetValue ("servername ", GetType(String) )
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim mycon As New EricDLL.Databas eConnection(sql Server, sqlDatabase)
Try
con.ConnectionS tring = mycon.Connectio nString
With cmd
.Connection = con
.CommandType = CommandType.Sto redProcedure
.CommandText = "SendBeginingIn ventoryToOracle "
.CommandTimeout = 60
End With
con.Open()
cmd.ExecuteNonQ uery()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()
End Try
End Sub
End Class
Is this setup properly?
Public Class OracleSnapshot
Private Shared m_instance As OracleSnapshot
Private Sub New()
Try
Dim t As System.Threadin g.Thread
t = New Threading.Threa d(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Enviro nment.NewLine)
m.Append(ex.ToS tring)
MessageBox.Show (m.ToString, "Error Creating Snapshot")
End Try
End Sub
Public Shared Function Activate() As OracleSnapshot
If m_instance Is Nothing Then
m_instance = New OracleSnapshot
End If
Return m_instance
End Function
Private Shared Sub runSnapshot()
Dim config As New Configuration.A ppSettingsReade r
Dim sqlDatabase, sqlServer As String
sqlDatabase = config.GetValue ("databasename" , GetType(String) )
sqlServer = config.GetValue ("servername ", GetType(String) )
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim mycon As New EricDLL.Databas eConnection(sql Server, sqlDatabase)
Try
con.ConnectionS tring = mycon.Connectio nString
With cmd
.Connection = con
.CommandType = CommandType.Sto redProcedure
.CommandText = "SendBeginingIn ventoryToOracle "
.CommandTimeout = 60
End With
con.Open()
cmd.ExecuteNonQ uery()
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()
End Try
End Sub
End Class