public async Task <StreamTask> AddTask(RtspIdentity rtspIdentity, Size convertResolution, RtspAuthentication authentication) { if (StreamTasks.TryGetValue(rtspIdentity, out var streamTask)) { if (streamTask.IsRunning) { return(streamTask); } } else { streamTask = new StreamTask(rtspIdentity, this); while (!StreamTasks.TryAdd(rtspIdentity, streamTask)) { } } if (!streamTask.IsRunning) { try { await streamTask.RunAsync(DefaultUsername ?? authentication.Credential.UserName, DefaultPassword ?? authentication.Credential.Password, convertResolution); } catch (Exception ex) { StreamTasks.TryRemove(rtspIdentity, out _); throw; } streamTask.ProcessExit += StreamTask_ProcessExit; } return(streamTask); }
private void StreamTask_ProcessExit(StreamTask obj) { while (!StreamTasks.TryRemove(obj.Identity, out _)) { } }
private void StreamTask_ProcessExit(StreamTask obj) { _heartBeatDictionary.TryRemove(obj.Identity, out _); }