WorkerSetFilteringState(FilteringState, Boolean) Method

Configures the behavior of the message filter for the default receive queue (index 0).

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public void SetFilteringState(
	FilteringState state,
	bool discardCurrentMessages = false
)

Parameters

state  FilteringState
Indicates the desired filtering behavior for the default receive queue (index 0).
discardCurrentMessages  Boolean  (Optional)
Indicates if messages currently contained by the default receive queue (index 0) are to be discarded on status change.

Remarks

The Worker registers 'ReceiveQueuesCount' receive queues. These are zero-based indexed. The first queue (index 0) is open by default when the object is created, meaning, its message filter is set to PassForAll. All other queues remain closed, that is, their filters are configured as BlockForAll. The methods associated with a receive queue are overloaded, allowing either the direct use of the default queue (index 0) without specifying an index, or the use of a specific queue by passing an index.

Example

The following example shows how to deactivate the default receive queue, after creating a Worker object.

In case of failure, an error messages is written to the console output using English as output language.

C#
// Create the object using the default configuration
//
Worker myWorker = new Worker();

// Set the filter of the default receive queue to discard all messages
//
myWorker.SetFilteringState(FilteringState.BlockForAll);

try
{
    // Activate the worker object
    //
    myWorker.Start();
    Console.WriteLine("The Worker object was activated successfully - Messages are being discarded.");

    // 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}");
}

See Also