Improve CJMS11 camera connection handling with timeout support
- Replaced synchronous connection retry logic with asynchronous timeout-based handling. - Added exception handling for connection attempts exceeding 1 second. - Introduced `EstablishCameraConnectionRepeticaly` with updated timeout intervals for retries.
This commit is contained in:
parent
d2ae5f3e83
commit
f5731c67a0
@ -637,7 +637,21 @@ namespace TBF.Rig.Network.Camera.CJMS11
|
||||
|
||||
private void EstablishCameraConnection(ref TcpClient camTcpClient, string localIP, int localPort)
|
||||
{
|
||||
int[] timeoutIntervals = new int[] { 100, 300, 500, 1000 };
|
||||
|
||||
var connectTask = camTcpClient.ConnectAsync(localIP, localPort);
|
||||
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(1));
|
||||
|
||||
var completedTask = Task.WhenAny(connectTask, timeoutTask).Result;
|
||||
|
||||
if (completedTask == timeoutTask)
|
||||
{
|
||||
throw new TimeoutException("Connection attempt timed out after 1 second.");
|
||||
}
|
||||
}
|
||||
|
||||
private void EstablishCameraConnectionRepeticaly(ref TcpClient camTcpClient, string localIP, int localPort)
|
||||
{
|
||||
int[] timeoutIntervals = new int[] { 500, 1000 };
|
||||
|
||||
foreach (int interval in timeoutIntervals)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user