# About StreamHandler

**URL:** <https://forum.commonvisionblox.com/t/about-streamhandler/635>\
**Category:** .Net API\
**Created:** [January 3, 2019, 2:20am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635 "2019-01-03T02:20:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![soultower](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@soultower](https://forum.commonvisionblox.com/u/soultower)\
**Post date:** [January 3, 2019, 2:20am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/1 "2019-01-03T02:20:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [January 3, 2019, 1:11pm UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/2 "2019-01-03T13:11:30Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![soultower](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@soultower](https://forum.commonvisionblox.com/u/soultower)\
**Post date:** [January 3, 2019, 2:19pm UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/3 "2019-01-03T14:19:01Z")

</div>

Thank you very much for your patience!

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [January 4, 2019, 7:40am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/4 "2019-01-04T07:40:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![George](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@George](https://forum.commonvisionblox.com/u/George)\
**Post date:** [January 19, 2022, 11:06am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/5 "2022-01-19T11:06:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![illusive](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/illusive/32/61_2.png) [@illusive](https://forum.commonvisionblox.com/u/illusive)\
**Post date:** [January 20, 2022, 7:03am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/6 "2022-01-20T07:03:18Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![George](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@George](https://forum.commonvisionblox.com/u/George)\
**Post date:** [January 20, 2022, 10:57am UTC](https://forum.commonvisionblox.com/t/about-streamhandler/635/7 "2022-01-20T10:57:01Z")

</div>

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