houlahan
asked on
Continuous queue
What im trying to do is create a logging queue that i can just enqueue items to when i need to and it will process the items in order of the item been queued. basically i want to be able to call something like
The queue:
Calling the enqueue:
Starting the queue:
Im not sure if this is the best way to do this, As this is a application that is going to be constantly running and using this queue I'm not sure if it would be up to doing what i need it to do.
Thanks for your help,
Houlahan.
queue.enque("Some Sql query")
and it will then process the SQL query when it has the resources to do so. What i have at the moment is:The queue:
Public Class SQLQueueManager
Public Shared Sqlitems As New Queue
Public Sub StartProcessing()
Dim t1 As New Threading.Thread(AddressOf Process)
t1.Start()
End Sub
Public Shared Sub Process()
Do
SyncLock Sqlitems.SyncRoot
If Sqlitems.Count = 0 Then
ElseIf Sqlitems.Count > 0 Then
SqlManager.ExecNonQuery(Sqlitems.Peek)
Sqlitems.Dequeue()
End If
End SyncLock
Loop
End Sub
End Class
Calling the enqueue:
Public Shared Sub InsertLog(ByVal dateAndTime As String, ByVal classStr As String, ByVal methordStr As String,
ByVal logType As String, ByVal message As String)
SQLQueueManager.Sqlitems.Enqueue(
"Insert log SET DateAndTime =NOW() ,Class ='" & classStr & "' ,Methord ='" & methordStr &
"' ,LogType ='" & logType & "' ,Message ='" & message & "' ")
End Sub
Starting the queue:
Dim sqlT As Thread = New Thread(AddressOf SQLQueueManager.Process)
sqlT.Start()
Im not sure if this is the best way to do this, As this is a application that is going to be constantly running and using this queue I'm not sure if it would be up to doing what i need it to do.
Thanks for your help,
Houlahan.
You can use the Queue class which is builtin. Then you can start a new thread which runs in the background and monitors the queue constantly. If it finds an item in queue, it processes it otherwise it sleeps for some time.
ASKER
I'm not entirely sure what you mean, I've had a look on msdn and i don't really understand how you would initiate this queue and then keep it alive so you can constantly add things to it do you know of any good examples of this?
Thanks
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.