Getting Started with CVB.Net

Processing with the StreamHandler (Windows Forms)

This post continues on the project created at:

The StreamHandler is designed to work like the Image ActiveX control (without being an ActiveX control :+1:). Thus it also has events to notify you on new images and errors:

  • NewImage event
  • Error event

If you know how the old Image ActiveX and Display ActiveX controls worked or you simply wondered how the Display knew that a new image arrived: The :cvb: Image has a PixelContentChanged event which the Display registers to. All our SDK methods changing the pixel data raise this event. That is why we didn’t need to implement the NewImage events to refresh the display in our simple CvbViewer app.

To implement the events we select our streamHandler on the Form’s Designer view and switch to the events in the Properties:

grafik
Here we double-click on both the Error and the NewImage events to register them. These events are called from the UI thread-context! So the good news is that you are able to directly manipulate your UI elements. The bad news is that, if you do lengthy processing, your UI hangs or at least becomes laggy.

There are ways on how to work around the lags. C# has the async/await keywords to do asynchronous processing. And probably you did see the NewImageAsync and ErrorAsync events. These are not the prefered solution, though – these are for the scenario that you started with the NewImage event and later found out that your UI becomes too laggy. This is an easier migration path to use async/await without rewriting your app. The prefered way is

Stemmer.Cvb.Async

Attention: It is out of the scope of this getting started to go into the details of asynchronous processing. Often this is also paired with parallel processing which is not a beginners topic anymore. If you are an expert: yes, we support that in multiple ways. :slight_smile:

1 Like