JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.04k stars 428 forks source link

program stops when i subscribe consecutively #871

Closed tmdwns7809 closed 3 years ago

tmdwns7809 commented 3 years ago

Describe the bug program stops when i subscribe consecutively. i think it falls in some deadlock

To Reproduce when i subcribe order book and then subscribe aggregated trade updates or vice versa, it stops at the 2nd subscribe function for example below


                var task = socketClient.FuturesUsdt.SubscribeToPartialOrderBookUpdatesAsync(itemData.Code, (int)Trading.instance.hoChart.Tag, 100, OnHoUpdates);
                task.Wait();

                var result = task.Result;
                if (!result.Success)
                    MessageBox.Show(result.Error.Message);

                var task2 = socketClient.FuturesUsdt.SubscribeToAggregatedTradeUpdatesAsync(itemData.Code, OnAggregatedTradeUpdates);    // it stops here
                task2.Wait();   // or here

                var result2 = task2.Result;
                if (!result2.Success)
                    MessageBox.Show(result2.Error.Message);

but when i do just one subscribe it doesn't stop and works well only happens when i subscribe 2 consecutively

please check this

Expected behavior A clear and concise description of what you expected to happen.

Debug logging mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext) 알 수 없음 // this is the stopped stack mscorlib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout) 알 수 없음 mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) 알 수 없음 mscorlib.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) 알 수 없음 mscorlib.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) 알 수 없음 mscorlib.dll!System.Threading.Tasks.Task.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) 알 수 없음 mscorlib.dll!System.Threading.Tasks.Task.Wait() 알 수 없음 [비동기 작업에서 대기 중, 두 번 클릭하거나 <Enter> 키를 눌러 비동기 호출 스택 보기]

BinanceHand.exe!BinanceHand.Form1.Trading_AggONandOFF(TradingLibrary.TradeItemData itemData, bool on) 줄 991 C# TradingLibrary.dll!TradingLibrary.Trading.Trading.SetAgg(TradingLibrary.TradeItemData itemData, bool on) 줄 1343 C# TradingLibrary.dll!TradingLibrary.Trading.Trading.ShowChart(TradingLibrary.TradeItemData itemData, System.Windows.Forms.DataVisualization.Charting.Chart chart) 줄 931 C# TradingLibrary.dll!TradingLibrary.Trading.Trading.SetRestView.AnonymousMethod__103_9() 줄 341 C# [네이티브에서 관리로 전환] [관리에서 네이티브로 전환] mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) 알 수 없음 mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) 알 수 없음 mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) 알 수 없음 mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) 알 수 없음 [네이티브에서 관리로 전환] [관리에서 네이티브로 전환] System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) 알 수 없음 System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) 알 수 없음 BinanceHand.exe!BinanceHand.Program.Main() 줄 20 C#

CarlPrentice commented 3 years ago

You probably have a deadlock caused by the use of Wait(). https://stackoverflow.com/questions/13140523/await-vs-task-wait-deadlock

tmdwns7809 commented 3 years ago

You probably have a deadlock caused by the use of Wait(). https://stackoverflow.com/questions/13140523/await-vs-task-wait-deadlock

thank you so much i think you are right i will check it out