22using System . Diagnostics ;
33using System . Text ;
44using System . Threading ;
5+ using System . Threading . Tasks ;
56using ServiceStack . Logging ;
67using ServiceStack . Text ;
78
@@ -40,7 +41,9 @@ public class RedisPubSubServer : IRedisPubSubServer
4041 private int noOfContinuousErrors = 0 ;
4142 private string lastExMsg = null ;
4243 private int status ;
44+ #if ! NETSTANDARD
4345 private Thread bgThread ; //Subscription controller thread
46+ #endif
4447 private long bgThreadCount = 0 ;
4548
4649 private const int NO = 0 ;
@@ -108,6 +111,9 @@ public IRedisPubSubServer Start()
108111 if ( OnStart != null )
109112 OnStart ( ) ;
110113
114+ #if NETSTANDARD
115+ RunLoop ( ) ;
116+ #else
111117 //Don't kill us if we're the thread that's retrying to Start() after a failure.
112118 if ( bgThread != Thread . CurrentThread )
113119 {
@@ -126,6 +132,7 @@ public IRedisPubSubServer Start()
126132 Log . Debug ( "Retrying RunLoop() on Thread: " + bgThread . Name ) ;
127133 RunLoop ( ) ;
128134 }
135+ #endif
129136 }
130137 catch ( Exception ex )
131138 {
@@ -327,8 +334,11 @@ private void RunLoop()
327334 if ( AutoRestart && Interlocked . CompareExchange ( ref status , 0 , 0 ) != Status . Disposed )
328335 {
329336 if ( WaitBeforeNextRestart != null )
337+ #if NETSTANDARD
338+ Task . Delay ( WaitBeforeNextRestart . Value ) ;
339+ #else
330340 Thread . Sleep ( WaitBeforeNextRestart . Value ) ;
331-
341+ #endif
332342 Start ( ) ;
333343 }
334344 }
@@ -428,6 +438,7 @@ public void Restart()
428438 Stop ( shouldRestart : true ) ;
429439 }
430440
441+ #if ! NETSTANDARD
431442 private void KillBgThreadIfExists ( )
432443 {
433444 if ( bgThread != null && bgThread . IsAlive )
@@ -447,6 +458,7 @@ private void KillBgThreadIfExists()
447458 bgThread = null ;
448459 }
449460 }
461+ #endif
450462
451463 private void SleepBackOffMultiplier ( int continuousErrorsCount )
452464 {
@@ -461,7 +473,11 @@ private void SleepBackOffMultiplier(int continuousErrorsCount)
461473 if ( Log . IsDebugEnabled )
462474 Log . Debug ( "Sleeping for {0}ms after {1} continuous errors" . Fmt ( nextTry , continuousErrorsCount ) ) ;
463475
476+ #if NETSTANDARD
477+ Task . Delay ( nextTry ) ;
478+ #else
464479 Thread . Sleep ( nextTry ) ;
480+ #endif
465481 }
466482
467483 public static class Operation //dep-free copy of WorkerOperation
@@ -555,6 +571,7 @@ public virtual void Dispose()
555571 Log . Error ( "Error OnDispose(): " , ex ) ;
556572 }
557573
574+ #if ! NETSTANDARD
558575 try
559576 {
560577 Thread . Sleep ( 100 ) ; //give it a small chance to die gracefully
@@ -564,6 +581,7 @@ public virtual void Dispose()
564581 {
565582 if ( this . OnError != null ) this . OnError ( ex ) ;
566583 }
584+ #endif
567585
568586 DisposeHeartbeatTimer ( ) ;
569587 }
0 commit comments