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!