About StreamHandler

I have a question about using the .net API.
How to use Event NewImageAsync As Func(Of Object, ImageEventArgs, Task) in "Class StreamHandler? What is the purpose of the task returned by the function pointed to?

The NewImageAsync event allows you to register an event handler that is itself declared as async and internally uses await to implement asynchronous processing of the newly arrived image data. Methods declared as async by means of the async keyword introduced in .Net 4.5 require a Task state which is why there is this third argument in the event’s signature. When registering an async handler, you will not actually use or even see the Task object:

public MainForm()
{
  InitializeComponent();
  ...
  streamHandler.NewImageAsync += StreamHandler_NewImageAsync;
  ...
}

private async System.Threading.Tasks.Task StreamHandler_NewImageAsync(object sender, Stemmer.Cvb.Forms.Components.ImageEventArgs arg)
{
  ...
  await DoAsyncProcessing(arg.Image);      
  ...
}

Keep in mind that an in many cases easier access to async acquisition is possible through the extension methods offered by Stemmer.Cvb.Async.AcquisitionExtensions (like with NewImageAsync the extension methods will in the documentation be shown with a Task return value, and like with NewImageAsync these Task objects basically serve the requirements for the async/await keywords and are usually not operated on directly.

Thank you very much for your patience!

1 Like

:slightly_smiling_face:
no need to thank for that - good questions are always welcome!

Hello,
I have a similar problem but with 5 cameras, so I have 5 async streamhandler events.
I need all those events have finished until I do processing.
I can not make it work properly.

Hi @George,

one thing you can do in this case is write an object with which you gather the acquisition state from the 5 different cameras (make sure to use lock properly) and then launch the processing (ideally in a thread of its own).

Ok, that is what I did at the beginning, I used a latch.
Thank you very much