DeviceBusyException
public sealed class DeviceBusyException : ThermalDeviceException
The camera would not carry the operation out, and may next time.
Derives from ThermalDeviceException, so code that already handles a device error keeps handling this. Catch this one first to tell it apart.
The distinction it exists for: an operation-mode switch that fails as SdkConfigurationException sends the reader to check the mode they asked for. On an Xi 400 over USB that is the wrong place to look: the camera accepts the mode, and the video format cannot be set while the previous stream is still tearing down. The SDK retries that four times over five seconds; once in six switches all four failed, and what the caller got back read as "you asked for something invalid".
Retrying is a reasonable response to this one, which is not true of the other errors here.
Opening a camera raises it too, which was not written down anywhere. Not only an operation-mode switch: ThermalCamera.Open and every overload of it, every overload of ThermalCamera.OpenAsync, and ThermalCamera.Reconnect raise it when another program holds the camera, and when this application holds it and is not handing it back. That has been true since version 12 and this type's remarks described only the mode switch, so a caller reading them would not have guarded an open for it.
Which of those happened is DeviceBusyException.Reason, and the three want different handling: one of them means the camera is not in use by anybody. DeviceBusyException.Holder and DeviceBusyException.ClaimPath carry the specifics, and are empty rather than guessed when the SDK cannot name them.
Example
try { camera = ThermalCamera.Open(device); } catch (DeviceBusyException error) { switch (error.Reason) { case DeviceBusyReason.ClaimedByAnotherProcess: // The only case worth showing as "in use by another // application". Holder names it when it can. tile.Status = error.Holder.Length > 0 ? $"In use by {error.Holder}" : "In use by another application"; break; case DeviceBusyReason.AlreadyOpenInThisProcess: // Our own bug. Retrying cannot help. tile.Status = "Already open in this application"; break; case DeviceBusyReason.HandoverInThisProcess: // We are still letting go of it. Try again shortly. tile.Status = "Closing…"; break; case DeviceBusyReason.FormatNotAccepted: // Nothing holds the camera. Do NOT say "in use". tile.Status = "The camera would not start streaming"; break; default: tile.Status = error.Message; break; } }
DeviceBusyException: constructors
public DeviceBusyException(string message)
Create the exception.
message: What went wrong.
public DeviceBusyException(string message, int status)
Create the exception with its native status.
message: What went wrong.status: The native status code.
public DeviceBusyException(string message, int status, DeviceBusyReason reason, string holder, string claimPath)
Create the exception with what refused it.
message: What went wrong.status: The native status code.reason: Which condition refused.holder: The program holding the claim, or an empty string.claimPath: The claim file, or an empty string.
DeviceBusyException: properties
public string ClaimPath { get; }
The claim file this refusal is about.
Worth putting in a support report: a claim nobody can account for is a stale lock file, and this says which one to look at.
public string Holder { get; }
The program holding the claim on the camera.
For showing to a person. Do not parse it, and do not test it to decide whether a camera is free; that is DeviceBusyException.Reason.
public DeviceBusyReason Reason { get; }
Which condition refused.
This type covers three unrelated conditions and they want different answers from an application. Another program has the camera is worth telling an operator about and worth retrying. You already have it open is this application's own bug and retrying cannot help. The format would not come up means the camera is free, so showing it as in use is simply wrong.
A named enum and not an int, because OptrisSdkException.Status's own documentation says a status code is for diagnostics and not for control flow. This one is for control flow.
Before this existed the only way to tell the three apart was to search Exception.Message for English, which is what a shipping client was doing, with Message.Contains("busy"), and which no longer even matches: the own-claim refusal does not contain the word.