Hi @Kamen , Welcome to Microsoft Q&A,
The System.ArgumentException
you are encountering with EventWaitHandle.WaitAll(WaitHandle[], Int32)
can indeed be perplexing, especially since the arguments appear to be valid.
List<EventWaitHandle> AllWHList = new List<EventWaitHandle>();
EventWaitHandle[] AllWH = new EventWaitHandle[ChannelsToWaitOn.Count];
foreach (Guid ChID in ChannelsToWaitOn)
{
EventWaitHandle EWH = RefProgram.GetChannelByID(ChID).RegisterForValueUpdateNotification(OUID);
if (EWH != null)
{
AllWHList.Add(EWH);
}
}
if (AllWHList.Count > 0)
{
AllWH = AllWHList.ToArray();
foreach (var handle in AllWH)
{
Console.WriteLine($"Handle: {handle}, SafeWaitHandle: {handle.SafeWaitHandle}, IsClosed: {handle.SafeWaitHandle.IsClosed}, IsInvalid: {handle.SafeWaitHandle.IsInvalid}");
}
if (AllWH.Length > 64)
{
throw new InvalidOperationException("Too many wait handles. Maximum allowed is 64.");
}
try
{
while (!EventWaitHandle.WaitAll(AllWH, (int)(ResolutionSec * 1000)) && !AbortExecution)
{
// Wait loop
}
}
catch (ArgumentException ex)
{
Console.WriteLine("ArgumentException: " + ex.Message);
// Additional logging or handling
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.