mirror of
				https://github.com/JKorf/CryptoExchange.Net
				synced 2025-10-31 02:17:45 +00:00 
			
		
		
		
	Merge pull request #141 from nathan-datusarator/master
Add checks for Disposed
This commit is contained in:
		
						commit
						8fe00693bd
					
				| @ -258,22 +258,30 @@ namespace CryptoExchange.Net.OrderBook | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             _subscription = startResult.Data; |             _subscription = startResult.Data; | ||||||
|             _subscription.ConnectionLost += () => |             _subscription.ConnectionLost += HandleConnectionLost; | ||||||
|             { |             _subscription.ConnectionClosed += HandleConnectionClosed; | ||||||
|  |             _subscription.ConnectionRestored += HandleConnectionRestored; | ||||||
|  | 
 | ||||||
|  |             Status = OrderBookStatus.Synced; | ||||||
|  |             return new CallResult<bool>(true); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         private void HandleConnectionLost() { | ||||||
|              log.Write(LogLevel.Warning, $"{Id} order book {Symbol} connection lost"); |              log.Write(LogLevel.Warning, $"{Id} order book {Symbol} connection lost"); | ||||||
|  |              if (Status != OrderBookStatus.Disposed) { | ||||||
|                 Status = OrderBookStatus.Reconnecting; |                 Status = OrderBookStatus.Reconnecting; | ||||||
|                 Reset(); |                 Reset(); | ||||||
|             }; |             } | ||||||
|             _subscription.ConnectionClosed += () => |         } | ||||||
|             { | 
 | ||||||
|  |         private void HandleConnectionClosed() { | ||||||
|             log.Write(LogLevel.Warning, $"{Id} order book {Symbol} disconnected"); |             log.Write(LogLevel.Warning, $"{Id} order book {Symbol} disconnected"); | ||||||
|             Status = OrderBookStatus.Disconnected; |             Status = OrderBookStatus.Disconnected; | ||||||
|             _ = StopAsync(); |             _ = StopAsync(); | ||||||
|             }; |         } | ||||||
| 
 | 
 | ||||||
|             _subscription.ConnectionRestored += async time => await ResyncAsync().ConfigureAwait(false); |         private async void HandleConnectionRestored(TimeSpan _) { | ||||||
|             Status = OrderBookStatus.Synced; |             await ResyncAsync().ConfigureAwait(false); | ||||||
|             return new CallResult<bool>(true); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <inheritdoc/> |         /// <inheritdoc/> | ||||||
| @ -286,8 +294,12 @@ namespace CryptoExchange.Net.OrderBook | |||||||
|             if (_processTask != null) |             if (_processTask != null) | ||||||
|                 await _processTask.ConfigureAwait(false); |                 await _processTask.ConfigureAwait(false); | ||||||
| 
 | 
 | ||||||
|             if (_subscription != null) |             if (_subscription != null) { | ||||||
|                 await _subscription.CloseAsync().ConfigureAwait(false); |                 await _subscription.CloseAsync().ConfigureAwait(false); | ||||||
|  |                 _subscription.ConnectionLost -= HandleConnectionLost; | ||||||
|  |                 _subscription.ConnectionClosed -= HandleConnectionClosed; | ||||||
|  |                 _subscription.ConnectionRestored -= HandleConnectionRestored; | ||||||
|  |             } | ||||||
|             log.Write(LogLevel.Trace, $"{Id} order book {Symbol} stopped"); |             log.Write(LogLevel.Trace, $"{Id} order book {Symbol} stopped"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -601,13 +613,13 @@ namespace CryptoExchange.Net.OrderBook | |||||||
| 
 | 
 | ||||||
|         private async Task ProcessQueue() |         private async Task ProcessQueue() | ||||||
|         { |         { | ||||||
|             while (Status != OrderBookStatus.Disconnected) |             while (Status != OrderBookStatus.Disconnected && Status != OrderBookStatus.Disposed) | ||||||
|             { |             { | ||||||
|                 await _queueEvent.WaitAsync().ConfigureAwait(false); |                 await _queueEvent.WaitAsync().ConfigureAwait(false); | ||||||
| 
 | 
 | ||||||
|                 while (_processQueue.TryDequeue(out var item)) |                 while (_processQueue.TryDequeue(out var item)) | ||||||
|                 { |                 { | ||||||
|                     if (Status == OrderBookStatus.Disconnected) |                     if (Status == OrderBookStatus.Disconnected || Status == OrderBookStatus.Disposed) | ||||||
|                         break; |                         break; | ||||||
| 
 | 
 | ||||||
|                     if (_stopProcessing) |                     if (_stopProcessing) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user