Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Imports System Imports System.Threading Imports System.Collections Namespace MonitorCS1 Class MonitorSample Private MAX_LOOP_TIME As Integer = 1000 Private m_smplQueue As Queue Public Sub New() m_smplQueue = New Queue() End Sub 'New Public Sub FirstThread() Dim counter As Integer = 0 SyncLock m_smplQueue While counter < MAX_LOOP_TIME 'Wait, if the queue is busy. Monitor.Wait(m_smplQueue) 'Push one element. m_smplQueue.Enqueue(counter) 'Release the waiting thread. Monitor.Pulse(m_smplQueue) counter += 1 End While End SyncLock End Sub 'FirstThread Public Sub SecondThread() SyncLock m_smplQueue 'Release the waiting thread. Monitor.Pulse(m_smplQueue) 'Wait in the loop while the queue is busy. 'Exit on the time-out when the first thread stops. While Monitor.Wait(m_smplQueue, 1000) 'Pop the first element. Dim counter As Integer = CInt(m_smplQueue.Dequeue()) 'Print the first element. Console.WriteLine(counter.ToString()) 'Release the waiting thread. Monitor.Pulse(m_smplQueue) End While End SyncLock End Sub 'SecondThread 'Return the number of queue elements. Public Function GetQueueCount() As Integer Return m_smplQueue.Count End Function 'GetQueueCount Public Shared Sub Main(args() As String) 'Create the MonitorSample object. Dim test As New MonitorSample() 'Create the first thread. Dim tFirst As New Thread(AddressOf test.FirstThread) 'Create the second thread. Dim tSecond As New Thread(AddressOf test.SecondThread) 'Start threads. tFirst.Start() tSecond.Start() 'wait to the end of the two threads tFirst.Join() tSecond.Join() 'Print the number of queue elements. Console.WriteLine(("Queue Count = " + test.GetQueueCount().ToString())) End Sub 'Main End Class 'MonitorSample End Namespace 'MonitorCS1
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.