473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Singleton-please verify usage

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.Threading.Thread
t = New Threading.Thread(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Environment.NewLine)
m.Append(ex.ToString)

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.AppSettingsReader
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.DatabaseConnection(sqlServer, sqlDatabase)

Try
con.ConnectionString = mycon.ConnectionString

With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SendBeginingInventoryToOracle"
.CommandTimeout = 60

End With
con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()

End Try
End Sub
End Class
Nov 21 '05 #1
2 1183
Thing is, what would anyone do with an instance of an OracleSnapshot object? The only methods in this class are Shared.

Also, you are creating a new thread for runSnapshot, but you are never starting it?
"ECathell" <ec******@nospam.com> wrote in message news:eU**************@TK2MSFTNGP10.phx.gbl...
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.Threading.Thread
t = New Threading.Thread(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Environment.NewLine)
m.Append(ex.ToString)

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.AppSettingsReader
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.DatabaseConnection(sqlServer, sqlDatabase)

Try
con.ConnectionString = mycon.ConnectionString

With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SendBeginingInventoryToOracle"
.CommandTimeout = 60

End With
con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()

End Try
End Sub
End Class
Nov 21 '05 #2
Yep I found that and fixed it..thanks

The sole reason for this class is to run the stored procedure. Only allowing it to be run once and running it on its own separate thread so that it doesn't lockup the interface.

--
--Eric Cathell, MCSA
"Marina" <so*****@nospam.com> wrote in message news:eL**************@TK2MSFTNGP12.phx.gbl...
Thing is, what would anyone do with an instance of an OracleSnapshot object? The only methods in this class are Shared.

Also, you are creating a new thread for runSnapshot, but you are never starting it?
"ECathell" <ec******@nospam.com> wrote in message news:eU**************@TK2MSFTNGP10.phx.gbl...
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.Threading.Thread
t = New Threading.Thread(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Environment.NewLine)
m.Append(ex.ToString)

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.AppSettingsReader
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.DatabaseConnection(sqlServer, sqlDatabase)

Try
con.ConnectionString = mycon.ConnectionString

With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SendBeginingInventoryToOracle"
.CommandTimeout = 60

End With
con.Open()

cmd.ExecuteNonQuery()

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()

End Try
End Sub
End Class
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sean Dettrick | last post by:
Hi, apologies for yet another Singleton posting. From reading around previous postings etc, I've cobbled together two Singleton template definitions - one that returns a reference, and one that...
16
by: cppaddict | last post by:
Hi, In this tutorial on singleton class in C++ (http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp) the author gives two implementations of a simple singleton class, claiming that...
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
1
by: Capstar | last post by:
Hi NG, I was reading about Singletons on devX. http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp This is their class: class Singleton { public: static Singleton* Instance();
7
by: Ethan | last post by:
Hi, I have a class defined as a "Singleton" (Design Pattern). The codes are attached below. My questions are: 1. Does it has mem leak? If no, when did the destructor called? If yes, how can I...
3
by: Harry | last post by:
Hi ppl I have a doubt on singleton class. I am writing a program below class singleton { private: singleton(){}; public: //way 1
3
by: Raider | last post by:
I need to have one object for each template argument(s) used. For example, I need to have one object of int. I tried the following code and it gives me all I want with Visual C++ 7.1. But is it...
12
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
5
by: sam_cit | last post by:
Hi everyone, I have the following code and it gives a linker error on MS vc++ 6.0. error LNK2001: unresolved external symbol "protected: __thiscall Singleton::Singleton(void)"...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.