public void ClearReceiveQueue(
int queueIndex
)
Public Sub ClearReceiveQueue (
queueIndex As Integer
)
public:
void ClearReceiveQueue(
int queueIndex
)
This implies, that an application can keep processing messages after a connection to a PCAN Channel has been terminated.
The following example shows how to clear the second receive queue (index 1).
In case of failure, an error messages is written to the console output using English as output language.
// Create the object using the default configuration
//
Worker myWorker = new Worker();
try
{
// Activate the worker object
//
myWorker.Start();
Console.WriteLine("The Worker object was activated successfully.");
// Set the second filter (index 1) to pass all messages
//
myWorker.SetFilteringState(1, FilteringState.PassForAll);
// Wait for sometime to get messages in the receive queue
//
Console.WriteLine("Waiting for messages......");
System.Threading.Thread.Sleep(5000);
// Get and show the amount of messages contained in the first and second receive queues
//
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount()} messages in the first receive queue. ");
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount(1)} messages in the second receive queue. ");
// Clear the second receive queue and show the amount of messages in the queues again
//
myWorker.ClearReceiveQueue(1);
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount()} messages in the first receive queue. ");
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount(1)} messages in the second receive queue, after clearing it. ");
// Deactivate the worker object, when it is no longer needed
//
myWorker.Stop();
Console.WriteLine("The Worker object was deactivated.");
}
catch(Exception ex)
{
Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}");
}
' Create the object using the default configuration
'
Dim myWorker As Worker = New Worker()
Try
' Activate the worker object
'
myWorker.Start()
Console.WriteLine("The Worker object was activated successfully.")
' Set the second filter (index 1) to pass all messages
'
myWorker.SetFilteringState(1, FilteringState.PassForAll)
' Wait for sometime to get messages in the receive queue
'
Console.WriteLine("Waiting for messages......")
Threading.Thread.Sleep(5000)
' Get And show the amount of messages contained in the first And second receive queues
'
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount()} messages in the first receive queue. ")
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount(1)} messages in the second receive queue. ")
' Clear the second receive queue and show the amount of messages in the queues again
'
myWorker.ClearReceiveQueue(1)
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount()} messages in the first receive queue. ")
Console.WriteLine($"There are {myWorker.GetAvailableMessagesCount(1)} messages in the second receive queue, after clearing it. ")
' Deactivate the worker object, when it is no longer needed
'
myWorker.[Stop]()
Console.WriteLine("The Worker object was deactivated.")
Catch ex As Exception
Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}")
End Try
// Create the object using the default configuration
//
Worker^ myWorker = gcnew Worker();
try
{
// Activate the worker object
//
myWorker->Start(false, false, false);
Console::WriteLine("The Worker object was activated successfully.");
// Set the second filter (index 1) to pass all messages
//
myWorker->SetFilteringState(1, FilteringState::PassForAll, false);
// Wait for sometime to get messages in the receive queue
//
Console::WriteLine("Waiting for messages......");
System::Threading::Thread::Sleep(5000);
// Get and show the amount of messages contained in the first and second receive queues
//
Console::WriteLine("There are {0} messages in the first receive queue. ", myWorker->GetAvailableMessagesCount());
Console::WriteLine("There are {0} messages in the second receive queue. ", myWorker->GetAvailableMessagesCount(1));
// Clear the second receive queue and show the amount of messages in the queues again
//
myWorker->ClearReceiveQueue(1);
Console::WriteLine("There are {0} messages in the first receive queue. ", myWorker->GetAvailableMessagesCount());
Console::WriteLine("There are {0} messages in the second receive queue, after clearing it. ", myWorker->GetAvailableMessagesCount(1));
// Deactivate the worker object, when it is no longer needed
//
myWorker->Stop(false, false, false);
Console::WriteLine("The Worker object was deactivated.");
}
catch (Exception^ ex)
{
Console::WriteLine("An exception occurred by activating the Worker object. {0}", ex->Message);
}
IndexOutOfRangeException | The queueIndex parameter value is out of range. This must be in the range [0...ReceiveQueuesCount-1]. |