Class OnDeviceCanStartEventArgs
- Namespace
- VisioForge.Core.Types.Events
- Assembly
- VisioForge.Core.dll
Provides data for the device startup validation event. This event allows applications to control whether a device should be allowed to start.
public class OnDeviceCanStartEventArgs : EventArgsInheritance
Inherited Members
Examples
// Example of implementing exclusive camera access
private string currentCameraPath = null;
captureDevice.OnDeviceCanStart += (sender, e) =>
{
// Check if this is a camera device
if (e.DeviceName.Contains("Camera") || e.DeviceName.Contains("Webcam"))
{
// Allow only one camera at a time
if (currentCameraPath == null || currentCameraPath == e.DevicePath)
{
e.CanStart = true;
currentCameraPath = e.DevicePath;
}
else
{
e.CanStart = false;
MessageBox.Show($"Camera {currentCameraPath} is already in use. Please stop it first.");
}
}
else
{
// Allow all non-camera devices
e.CanStart = true;
}
};
// Example of implementing user permission check
captureDevice.OnDeviceCanStart += async (sender, e) =>
{
// Check user permissions for device access
var hasPermission = await CheckUserDevicePermission(e.DeviceName, e.DevicePath);
if (!hasPermission)
{
e.CanStart = false;
LogDeviceAccessDenied(e.DeviceName, "User permission denied");
}
else
{
e.CanStart = true;
LogDeviceAccessGranted(e.DeviceName);
}
};
Remarks
This event is raised before a device (camera, microphone, etc.) is started, giving the application a chance to prevent the device from starting based on custom logic. This is useful for implementing device access control, exclusive device usage, or conditional device activation based on application state. The event handler can set the VisioForge.Core.Types.Events.OnDeviceCanStartEventArgs.CanStart property to control the device startup.
Constructors
OnDeviceCanStartEventArgs(string, string)
Initializes a new instance of the VisioForge.Core.Types.Events.OnDeviceCanStartEventArgs class.
public OnDeviceCanStartEventArgs(string deviceName, string devicePath)Parameters
Properties
CanStart
Gets or sets a value indicating whether the device is allowed to start.
public bool CanStart { get; set; }Property Value
DeviceName
Gets the friendly name of the device attempting to start.
public string DeviceName { get; }Property Value
DevicePath
Gets the system path or identifier of the device.
public string DevicePath { get; }