# Example

This example shows a way to handle processing of an Image when the ImageAcquisition is happening faster than the rate at which the ImageProcessing Task can process the image.

Note: This example would be suited to a physical process that had short fast bursts of action, followed by gaps to give the image processing task time to catch up

### AcquisitionTask (Triggered by Camera.ImageAcquired event)

Within the AcquisitionTask, we create a Script Block which receives the acquired image and Timestamp from the Camera. This Script Block has the following script to take the input parameters, create a Tuple with their values, then call the TriggerObject method to trigger SoftEvent0.

Copy

    // After image acquire pass image with timestamp through to be processed.
    // Add $ItemNumber tag to keep track of item.
    $ItemNumber++;
    int itemNum = $ItemNumber;
    var ImageData = Tuple.Create(TimeStamp, Image, itemNum);

    // There are 4 SoftEvents that can be used to trigger Tasks.
    // We need to enter the SoftEvent number (0-3) as a parameter
    // (depending on which SoftEvent we want to Trigger).
    // Also enter as a parameter the ImageData Tuple that we just created.

    $SoftEvents.TriggerObject(0, ImageData);

### ProcessingTask (Triggered by SoftEvents.Event0)

Within the ProcessingTask, we set the Task Trigger to Event and choose SoftEvents.Event0 as the event that will trigger an execution of the Task.

The SoftEvent Block is configured with SoftEvent Id of 0 (matching the Id of the Task Trigger Event0). The Output pin of the block is configured to use an Output Type of Tuple<long, ICogImage, int> to match the expected Data that is passed through from the TriggerObject script.

Use the … button in the Output Type property of the SoftEvent block to select a Type matching the Tuple passed to the TriggerObject script.

We can then link the Output pin of the block to one or more blocks to use the Data that is passed through.

For each script block in the following example, set the Input pin Type to a Tuple matching the Output pin of the SoftEvent block. We can then access the elements of the Tuple within the script (for example, myTuple.Item1, myTuple.Item2)

The Task will be run once for each time the TriggerObject script is called. If the Task cannot execute faster than the rate that SoftEvents are being Triggered, the Trigger will be added to a Queue and executed as fast as possible. The Task Property QueueLength can be used to determine how many Events can be added to the Queue before they are ignored. The default setting for this is 32.