burakoner / ApiSharp

HTTP, WebSocket, Tcp Socket client library for .NET featuring automatic serialization and deserialization and really easy to implement
Apache License 2.0
6 stars 1 forks source link

Exception in AsyncResetEvent.cs #2

Closed fomines closed 11 months ago

fomines commented 11 months ago

Hello. Thanks for the library! Please tell me, an exception occurs in my application and the application crashes. How can I fix it so that there are no problems? Thank you! Exception in ApiSharp\Models\AsyncResetEvent.cs:line 51. Stack: "System.AggregateException: One or more errors occurred. (Collection was modified; enumeration operation may not execute.)\r\n ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.\r\n at System.Collections.Generic.Queue1.Enumerator.MoveNext()\r\n at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source, Int32& length)\r\n at System.Collections.Generic.Queue1..ctor(IEnumerable1 collection)\r\n at ApiSharp.Models.AsyncResetEvent.<>c__DisplayClass5_0.b__0() in E:\Github\ApiSharp\ApiSharp\Models\AsyncResetEvent.cs:line 51\r\n

Thx.

dreamzgj commented 11 months ago

var registration = cancellationSource.Token.Register(() => { tcs.TrySetResult(false);

                    List<TaskCompletionSource<bool>> _tmp_waits = _waits.ToList();
                    // Not the cleanest but it works
                    _waits = new Queue<TaskCompletionSource<bool>>(_tmp_waits.Where(i => i != tcs));
                }, useSynchronizationContext: true);  //here !!! use true can fix
burakoner commented 11 months ago

Fixed in Version 2.0.5