thanks for the feedback - always happy to help
For what you plan, I recommend having a look at a tutorial that ships with the CVB.Net wrappers called “StreamDisplay”. You should be able to find it in the folder %CVB%\Tutorial\Image Manager\Cvb.Net\StreamDisplay. As it is, it does nothing else but show a live image from a selectable image source, but it illustrates how to implement a continuous image acquisition with the .Net wrappers. Spoiler: You won’t find any
Stream.Wait() calls in it
Stream.Wait() is a valid approach to continuous acquisition (and in fact the one that gives you a fairly high degree of control over what is happening when and where), it has the potential to become a bit clunky if you have to match it up with a GUI framework, because in the scenario you describe,
Stream.Wait() should be called asynchronously to keep the UI responsive. There are basically two ways to achieve this without resorting to setting up and managing a dedicated acquisition thread:
- If you are using at least C# 5 which gives you access to the keywords
await you can use the
Stream.WaitAsync() method in what looks more like a simple loop but in fact runs asynchronously to your UI. And example for this may be found in the WpfGenICam tutorial:
private async void menuGrab_Checked(object sender, RoutedEventArgs e)
menuOpen.IsEnabled = false; // keep people from loading a new driver while acquisition is still running
using (StreamImage image = await Device.Stream.WaitAsync())
// add processing here...
// acquisition was aborted
menuOpen.IsEnabled = true;
- As mentioned previously,
await is not available for every project, plus traditionally-minded Forms developers feel more at home with event handlers. Therefore, CVB.Net implements the
StreamHandler component (Stemmer.Cvb.Forms.dll, namespace
Stemmer.Cvb.Forms.Components). This object has a
Stream property to which a loaded stream is assigned. With the
Stop() method you can control acquisition and subscription to the component’s
NewImage event (and ideally also the
Error event) allows you to react to new images and things that might have gone wrong during acquisition.
Note that these events are fired in the UI thread’s context, which means that you can manipulate the UI in any way you want in the handlers. If, however, processing is expected to take a significant amount of time, doing the processing right inside the handler is not encouraged.
Have a look at the contents of MainForm.Streaming.cs in the StreamDisplay tutorial for code samples.