>>public static myCons >>{ >> Queue _connQueue; >> public myCons() >> { >> this._connQueue = new Queue(100); >> for (int i = 0; i < 100; i++) >> { >> this._connQueue.Enqueue( MyNewCon() ); >> } >> } >> public static OleDbConnection GetConnectionFromQueue() >> { >> return this._connQueue.Dequeue(); >> } >> public static ReturnConnectionToQueue(OleDbConnection con) >> { >> this._connQueue.Enqueue(con); >> } >>} >> >>// some connection requiring code >>OleDbConnection myCon = MyCons.GetConnectionFromQueue(); >>myCon.Open(); >>// do something with connection >>myCon.Close(); >>MyCons.ReturnConnectionToQueue(myCon); >>>
>Imports System.Data >Imports System.Data.Common >Imports System.Data.OleDb >Imports System.Data.SqlClient >Imports System.Data.Odbc > >Namespace Framework > > Public Class QueueConnection > > Dim oQueue As Queue = New Queue > > Public Function Initialize() As Boolean > Dim lnCounter As Integer = 0 > > oQueue = New Queue(100) > > For lnCounter = 1 To 100 > oQueue.Enqueue(MyNewCon()) > Next > > Return True > End Function > > Public Function GetConnectionFromQueue() As OleDbConnection > Return oQueue.Dequeue() > End Function > > Public Function ReturnConnectionToQueue(ByVal toConnection As OleDbConnection) As Boolean > oQueue.Enqueue(toConnection) > Return True > End Function > > End Class > >End Namespace >>