@@ -717,23 +717,25 @@ private async Task Worker()
717
717
if ( CurrentOnly ) url = CreateCurrentUrl ( Authority , Device , Interval , _streamPath ) ;
718
718
719
719
// Create and Start the Stream
720
- _stream = new MTConnectHttpClientStream ( url , DocumentFormat ) ;
721
- _stream . Timeout = Heartbeat * 3 ;
722
- _stream . ContentEncodings = ContentEncodings ;
723
- _stream . ContentType = ContentType ;
724
- _stream . Starting += ( s , o ) => StreamStarting ? . Invoke ( this , url ) ;
725
- _stream . Started += ( s , o ) => StreamStarted ? . Invoke ( this , url ) ;
726
- _stream . Stopping += ( s , o ) => StreamStopping ? . Invoke ( this , url ) ;
727
- _stream . Stopped += ( s , o ) => StreamStopped ? . Invoke ( this , url ) ;
728
- _stream . DocumentReceived += ( s , doc ) => ProcessSampleDocument ( doc , _stop . Token ) ;
729
- _stream . ErrorReceived += ( s , doc ) => ProcessSampleError ( doc ) ;
730
- _stream . FormatError += ( s , r ) => FormatError ? . Invoke ( this , r ) ;
731
- _stream . ConnectionError += ( s , ex ) => ConnectionError ? . Invoke ( this , ex ) ;
732
- _stream . InternalError += ( s , ex ) => InternalError ? . Invoke ( this , ex ) ;
733
-
734
- // Run Stream (Blocking call)
735
- await _stream . Run ( _stop . Token ) ;
736
-
720
+ using ( _stream = new MTConnectHttpClientStream ( url , DocumentFormat ) )
721
+ {
722
+ _stream . Timeout = Heartbeat * 3 ;
723
+ _stream . ContentEncodings = ContentEncodings ;
724
+ _stream . ContentType = ContentType ;
725
+ _stream . Starting += ( s , o ) => StreamStarting ? . Invoke ( this , url ) ;
726
+ _stream . Started += ( s , o ) => StreamStarted ? . Invoke ( this , url ) ;
727
+ _stream . Stopping += ( s , o ) => StreamStopping ? . Invoke ( this , url ) ;
728
+ _stream . Stopped += ( s , o ) => StreamStopped ? . Invoke ( this , url ) ;
729
+ _stream . DocumentReceived += ( s , doc ) => ProcessSampleDocument ( doc , _stop . Token ) ;
730
+ _stream . ErrorReceived += ( s , doc ) => ProcessSampleError ( doc ) ;
731
+ _stream . FormatError += ( s , r ) => FormatError ? . Invoke ( this , r ) ;
732
+ _stream . ConnectionError += ( s , ex ) => ConnectionError ? . Invoke ( this , ex ) ;
733
+ _stream . InternalError += ( s , ex ) => InternalError ? . Invoke ( this , ex ) ;
734
+
735
+ // Run Stream (Blocking call)
736
+ await _stream . Run ( _stop . Token ) ;
737
+ }
738
+
737
739
initialRequest = false ;
738
740
739
741
if ( ! _stop . Token . IsCancellationRequested )
0 commit comments