瀏覽代碼

First pass over a subset of the code.

Bart De Smet 5 年之前
父節點
當前提交
37890db79d
共有 31 個文件被更改,包括 142 次插入131 次删除
  1. 3 3
      Rx.NET/Source/src/System.Reactive/Concurrency/DefaultScheduler.cs
  2. 4 4
      Rx.NET/Source/src/System.Reactive/Concurrency/EventLoopScheduler.cs
  3. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs
  4. 2 2
      Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs
  5. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/NewThreadScheduler.cs
  6. 15 15
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs
  7. 8 8
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs
  8. 3 3
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs
  9. 9 9
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
  10. 3 3
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
  11. 2 2
      Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs
  12. 3 3
      Rx.NET/Source/src/System.Reactive/Concurrency/TaskPoolScheduler.cs
  13. 2 2
      Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.Windows.cs
  14. 7 7
      Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs
  15. 2 2
      Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs
  16. 10 6
      Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs
  17. 1 1
      Rx.NET/Source/src/System.Reactive/Disposables/ContextDisposable.cs
  18. 3 3
      Rx.NET/Source/src/System.Reactive/Internal/AsyncLockObserver.cs
  19. 2 2
      Rx.NET/Source/src/System.Reactive/Internal/Producer.cs
  20. 2 2
      Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs
  21. 6 6
      Rx.NET/Source/src/System.Reactive/Internal/Stubs.cs
  22. 2 2
      Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs
  23. 2 2
      Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/DispatcherScheduler.cs
  24. 2 2
      Rx.NET/Source/src/System.Reactive/Platforms/UWP/Concurrency/CoreDispatcherScheduler.cs
  25. 9 9
      Rx.NET/Source/src/System.Reactive/Platforms/UWP/Foundation/AsyncInfoExtensions.cs
  26. 2 2
      Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/CoreDispatcherObservable.cs
  27. 1 1
      Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/WindowsObservable.Events.cs
  28. 2 2
      Rx.NET/Source/src/System.Reactive/Platforms/Windows/ThreadPoolTimerExtensions.cs
  29. 1 1
      Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs
  30. 32 25
      Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs
  31. 二進制
      Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/AppPackages/Tests.System.Reactive.Uwp.DeviceRunner_1.0.0.0_x86_Debug_Test/Tests.System.Reactive.Uwp.DeviceRunner_1.0.0.0_x86_Debug.appx

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/DefaultScheduler.cs

@@ -42,7 +42,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
             var workItem = new UserWorkItem<TState>(this, state, action);
 
 
             workItem.CancelQueueDisposable = Cal.QueueUserWorkItem(
             workItem.CancelQueueDisposable = Cal.QueueUserWorkItem(
-                closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
                 workItem);
                 workItem);
 
 
             return workItem;
             return workItem;
@@ -73,7 +73,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
             var workItem = new UserWorkItem<TState>(this, state, action);
 
 
             workItem.CancelQueueDisposable = Cal.StartTimer(
             workItem.CancelQueueDisposable = Cal.StartTimer(
-                closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
                 workItem,
                 workItem,
                 dt);
                 dt);
 
 
@@ -124,7 +124,7 @@ namespace System.Reactive.Concurrency
             {
             {
                 _gate.Wait(
                 _gate.Wait(
                     this,
                     this,
-                    closureWorkItem => closureWorkItem._state = closureWorkItem._action(closureWorkItem._state));
+                    static closureWorkItem => closureWorkItem._state = closureWorkItem._action(closureWorkItem._state));
             }
             }
 
 
             public void Dispose()
             public void Dispose()

+ 4 - 4
Rx.NET/Source/src/System.Reactive/Concurrency/EventLoopScheduler.cs

@@ -82,7 +82,7 @@ namespace System.Reactive.Concurrency
         /// Creates an object that schedules units of work on a designated thread.
         /// Creates an object that schedules units of work on a designated thread.
         /// </summary>
         /// </summary>
         public EventLoopScheduler()
         public EventLoopScheduler()
-            : this(a => new Thread(a) { Name = "Event Loop " + Interlocked.Increment(ref _counter), IsBackground = true })
+            : this(static a => new Thread(a) { Name = "Event Loop " + Interlocked.Increment(ref _counter), IsBackground = true })
         {
         {
         }
         }
 
 
@@ -218,18 +218,18 @@ namespace System.Reactive.Concurrency
                 _scheduler = scheduler;
                 _scheduler = scheduler;
                 _next = scheduler._stopwatch.Elapsed + period;
                 _next = scheduler._stopwatch.Elapsed + period;
 
 
-                Disposable.TrySetSingle(ref _task, scheduler.Schedule(this, _next - scheduler._stopwatch.Elapsed, (_, s) => s.Tick(_)));
+                Disposable.TrySetSingle(ref _task, scheduler.Schedule(this, _next - scheduler._stopwatch.Elapsed, static (_, s) => s.Tick(_)));
             }
             }
 
 
             private IDisposable Tick(IScheduler self)
             private IDisposable Tick(IScheduler self)
             {
             {
                 _next += _period;
                 _next += _period;
 
 
-                Disposable.TrySetMultiple(ref _task, self.Schedule(this, _next - _scheduler._stopwatch.Elapsed, (_, s) => s.Tick(_)));
+                Disposable.TrySetMultiple(ref _task, self.Schedule(this, _next - _scheduler._stopwatch.Elapsed, static (_, s) => s.Tick(_)));
 
 
                 _gate.Wait(
                 _gate.Wait(
                     this,
                     this,
-                    closureWorkItem => closureWorkItem._state = closureWorkItem._action(closureWorkItem._state));
+                    static closureWorkItem => closureWorkItem._state = closureWorkItem._action(closureWorkItem._state));
 
 
                 return Disposable.Empty;
                 return Disposable.Empty;
             }
             }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs

@@ -12,7 +12,7 @@ namespace System.Reactive.Concurrency
     /// <seealso cref="Scheduler.Immediate">Singleton instance of this type exposed through this static property.</seealso>
     /// <seealso cref="Scheduler.Immediate">Singleton instance of this type exposed through this static property.</seealso>
     public sealed class ImmediateScheduler : LocalScheduler
     public sealed class ImmediateScheduler : LocalScheduler
     {
     {
-        private static readonly Lazy<ImmediateScheduler> _instance = new Lazy<ImmediateScheduler>(() => new ImmediateScheduler());
+        private static readonly Lazy<ImmediateScheduler> _instance = new Lazy<ImmediateScheduler>(static () => new ImmediateScheduler());
 
 
         private ImmediateScheduler()
         private ImmediateScheduler()
         {
         {

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs

@@ -195,7 +195,7 @@ namespace System.Reactive.Concurrency
                 // (though it should).
                 // (though it should).
                 //
                 //
                 var dueTime = Scheduler.Normalize(item.DueTime - item.Scheduler.Now);
                 var dueTime = Scheduler.Normalize(item.DueTime - item.Scheduler.Now);
-                d.Disposable = item.Scheduler.Schedule((@this: this, d), dueTime, (self, tuple) => [email protected](self, tuple.d));
+                d.Disposable = item.Scheduler.Schedule((@this: this, d), dueTime, static (self, tuple) => [email protected](self, tuple.d));
             }
             }
         }
         }
 
 
@@ -333,7 +333,7 @@ namespace System.Reactive.Concurrency
                 var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MaxSupportedTimer.Ticks));
                 var dueCapped = TimeSpan.FromTicks(Math.Min(dueEarly.Ticks, MaxSupportedTimer.Ticks));
 
 
                 _nextLongTermWorkItem = next;
                 _nextLongTermWorkItem = next;
-                NextLongTermTimer.Disposable = ConcurrencyAbstractionLayer.Current.StartTimer(_ => EvaluateLongTermQueue(), null, dueCapped);
+                NextLongTermTimer.Disposable = ConcurrencyAbstractionLayer.Current.StartTimer(static _ => EvaluateLongTermQueue(), null, dueCapped);
             }
             }
         }
         }
 
 

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Concurrency/NewThreadScheduler.cs

@@ -12,7 +12,7 @@ namespace System.Reactive.Concurrency
     /// </summary>
     /// </summary>
     public sealed class NewThreadScheduler : LocalScheduler, ISchedulerLongRunning, ISchedulerPeriodic
     public sealed class NewThreadScheduler : LocalScheduler, ISchedulerLongRunning, ISchedulerPeriodic
     {
     {
-        private static readonly Lazy<NewThreadScheduler> Instance = new Lazy<NewThreadScheduler>(() => new NewThreadScheduler());
+        private static readonly Lazy<NewThreadScheduler> Instance = new Lazy<NewThreadScheduler>(static () => new NewThreadScheduler());
 
 
         private readonly Func<ThreadStart, Thread> _threadFactory;
         private readonly Func<ThreadStart, Thread> _threadFactory;
 
 

+ 15 - 15
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs

@@ -21,11 +21,11 @@ namespace System.Reactive.Concurrency
                     return Disposable.Empty;
                     return Disposable.Empty;
 
 
                 action(new CancelableScheduler(self, _cts.Token), s, _cts.Token).ContinueWith(
                 action(new CancelableScheduler(self, _cts.Token), s, _cts.Token).ContinueWith(
-                    (t, thisObject) =>
+                    static (t, thisObject) =>
                     {
                     {
                         var @this = (AsyncInvocation<TState>)thisObject;
                         var @this = (AsyncInvocation<TState>)thisObject;
 
 
-                        t.Exception?.Handle(e => e is OperationCanceledException);
+                        t.Exception?.Handle(static e => e is OperationCanceledException);
 
 
                         Disposable.SetSingle(ref @this._run, t.Result);
                         Disposable.SetSingle(ref @this._run, t.Result);
                     },
                     },
@@ -218,7 +218,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -240,7 +240,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -313,7 +313,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, dueTime, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -336,7 +336,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, dueTime, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -409,7 +409,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, dueTime, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -432,37 +432,37 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return ScheduleAsync_(scheduler, action, dueTime, (self, closureAction, ct) => closureAction(self, ct));
+            return ScheduleAsync_(scheduler, action, dueTime, static (self, closureAction, ct) => closureAction(self, ct));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
-            return scheduler.Schedule((state, action), (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
-            return scheduler.Schedule((state, action), (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
-            return scheduler.Schedule((state, action), dueTime, (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), dueTime, static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
-            return scheduler.Schedule((state, action), dueTime, (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), dueTime, static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
-            return scheduler.Schedule((state, action), dueTime, (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), dueTime, static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
-            return scheduler.Schedule((state, action), dueTime, (self, t) => InvokeAsync(self, t.state, t.action));
+            return scheduler.Schedule((state, action), dueTime, static (self, t) => InvokeAsync(self, t.state, t.action));
         }
         }
 
 
         private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
@@ -472,7 +472,7 @@ namespace System.Reactive.Concurrency
 
 
         private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task> action)
         private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
-            return InvokeAsync(self, (action, state: s), (self_, t, ct) => t.action(self_, t.state, ct).ContinueWith(_ => Disposable.Empty));
+            return InvokeAsync(self, (action, state: s), static (self_, t, ct) => t.action(self_, t.state, ct).ContinueWith(static _ => Disposable.Empty));
         }
         }
 
 
         private static CancellationToken GetCancellationToken(this IScheduler scheduler)
         private static CancellationToken GetCancellationToken(this IScheduler scheduler)

+ 8 - 8
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs

@@ -27,7 +27,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule(action, (_action, self) => _action(() => self(_action)));
+            return scheduler.Schedule(action, static (a, self) => a(() => self(a)));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -51,7 +51,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule((state, action), (s, p) => InvokeRec1(s, p));
+            return scheduler.Schedule((state, action), static (s, p) => InvokeRec1(s, p));
         }
         }
 
 
         private static IDisposable InvokeRec1<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState>> action) tuple)
         private static IDisposable InvokeRec1<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState>> action) tuple)
@@ -81,7 +81,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule(action, dueTime, (_action, self) => _action(dt => self(_action, dt)));
+            return scheduler.Schedule(action, dueTime, static (a, self) => a(ts => self(a, ts)));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -106,7 +106,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule((state, action), dueTime, (s, p) => InvokeRec2(s, p));
+            return scheduler.Schedule((state, action), dueTime, static (s, p) => InvokeRec2(s, p));
         }
         }
 
 
         private static IDisposable InvokeRec2<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState, TimeSpan>> action) tuple)
         private static IDisposable InvokeRec2<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState, TimeSpan>> action) tuple)
@@ -136,7 +136,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule(action, dueTime, (_action, self) => _action(dt => self(_action, dt)));
+            return scheduler.Schedule(action, dueTime, static (a, self) => a(dt => self(a, dt)));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -161,7 +161,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.Schedule((state, action), dueTime, (s, p) => InvokeRec3(s, p));
+            return scheduler.Schedule((state, action), dueTime, static (s, p) => InvokeRec3(s, p));
         }
         }
 
 
         private static IDisposable InvokeRec3<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState, DateTimeOffset>> action) tuple)
         private static IDisposable InvokeRec3<TState>(IScheduler scheduler, (TState state, Action<TState, Action<TState, DateTimeOffset>> action) tuple)
@@ -206,7 +206,7 @@ namespace System.Reactive.Concurrency
                 var sad = new SingleAssignmentDisposable();
                 var sad = new SingleAssignmentDisposable();
 
 
                 Group.Add(sad);
                 Group.Add(sad);
-                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), nextState =>
+                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), static nextState =>
                 {
                 {
                     [email protected](nextState.sad);
                     [email protected](nextState.sad);
                     [email protected](nextState.state);
                     [email protected](nextState.state);
@@ -263,7 +263,7 @@ namespace System.Reactive.Concurrency
                 var sad = new SingleAssignmentDisposable();
                 var sad = new SingleAssignmentDisposable();
 
 
                 Group.Add(sad);
                 Group.Add(sad);
-                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), dtOffset, nextState => {
+                sad.Disposable = Scheduler.ScheduleAction((state, sad, @this: this), dtOffset, static nextState => {
                     [email protected](nextState.sad);
                     [email protected](nextState.sad);
                     [email protected](nextState.state);
                     [email protected](nextState.state);
                 });
                 });

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs

@@ -76,7 +76,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return SchedulePeriodic_(scheduler, (state, action), period, t => { t.action(t.state); return t; });
+            return SchedulePeriodic_(scheduler, (state, action), period, static t => { t.action(t.state); return t; });
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -108,7 +108,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return SchedulePeriodic_(scheduler, action, period, a => { a(); return a; });
+            return SchedulePeriodic_(scheduler, action, period, static a => { a(); return a; });
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -377,7 +377,7 @@ namespace System.Reactive.Concurrency
                 _nextDue = _period;
                 _nextDue = _period;
                 _runState = Running;
                 _runState = Running;
 
 
-                Disposable.TrySetSingle(ref _task, _scheduler.Schedule(this, _nextDue, (@this, a) => @this.Tick(a)));
+                Disposable.TrySetSingle(ref _task, _scheduler.Schedule(this, _nextDue, static (@this, a) => @this.Tick(a)));
                 return this;
                 return this;
             }
             }
 
 

+ 9 - 9
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs

@@ -34,7 +34,7 @@ namespace System.Reactive.Concurrency
             // the anonymous lambda can be replaced by the method group again. Until then,
             // the anonymous lambda can be replaced by the method group again. Until then,
             // to avoid the repetition of code, the call to Invoke is left intact.
             // to avoid the repetition of code, the call to Invoke is left intact.
             // Watch https://github.com/dotnet/roslyn/issues/5835
             // Watch https://github.com/dotnet/roslyn/issues/5835
-            return scheduler.Schedule(action, (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, static (s, a) => Invoke(s, a));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -85,7 +85,7 @@ namespace System.Reactive.Concurrency
 
 
             return scheduler.Schedule(
             return scheduler.Schedule(
                 (action, state),
                 (action, state),
-                (_, tuple) => tuple.action(tuple.state));
+                static (_, tuple) => tuple.action(tuple.state));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -109,7 +109,7 @@ namespace System.Reactive.Concurrency
             }
             }
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -134,7 +134,7 @@ namespace System.Reactive.Concurrency
             }
             }
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -154,7 +154,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -178,7 +178,7 @@ namespace System.Reactive.Concurrency
             }
             }
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule(action, dueTime, (s, a) => Invoke(s, a));
+            return scheduler.Schedule(action, dueTime, static (s, a) => Invoke(s, a));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -203,7 +203,7 @@ namespace System.Reactive.Concurrency
             }
             }
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -223,7 +223,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
 
 
             // See note above.
             // See note above.
-            return scheduler.Schedule((state, action), dueTime, (s, tuple) => Invoke(s, tuple));
+            return scheduler.Schedule((state, action), dueTime, static (s, tuple) => Invoke(s, tuple));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -245,7 +245,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.ScheduleLongRunning(action, (a, c) => a(c));
+            return scheduler.ScheduleLongRunning(action, static (a, c) => a(c));
         }
         }
 
 
         private static IDisposable Invoke(IScheduler scheduler, Action action)
         private static IDisposable Invoke(IScheduler scheduler, Action action)

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs

@@ -60,7 +60,7 @@ namespace System.Reactive.Concurrency
         //
         //
 
 
 
 
-        private static readonly Lazy<IScheduler> _threadPool = new Lazy<IScheduler>(() => Initialize("ThreadPool"));
+        private static readonly Lazy<IScheduler> _threadPool = new Lazy<IScheduler>(static () => Initialize("ThreadPool"));
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work on the thread pool.
         /// Gets a scheduler that schedules work on the thread pool.
@@ -68,7 +68,7 @@ namespace System.Reactive.Concurrency
         [Obsolete(Constants_Core.ObsoleteSchedulerThreadpool)]
         [Obsolete(Constants_Core.ObsoleteSchedulerThreadpool)]
         public static IScheduler ThreadPool => _threadPool.Value;
         public static IScheduler ThreadPool => _threadPool.Value;
 
 
-        private static readonly Lazy<IScheduler> _newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));
+        private static readonly Lazy<IScheduler> _newThread = new Lazy<IScheduler>(static () => Initialize("NewThread"));
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work on a new thread using default thread creation options.
         /// Gets a scheduler that schedules work on a new thread using default thread creation options.
@@ -76,7 +76,7 @@ namespace System.Reactive.Concurrency
         [Obsolete(Constants_Core.ObsoleteSchedulerNewthread)]
         [Obsolete(Constants_Core.ObsoleteSchedulerNewthread)]
         public static IScheduler NewThread => _newThread.Value;
         public static IScheduler NewThread => _newThread.Value;
 
 
-        private static readonly Lazy<IScheduler> _taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));
+        private static readonly Lazy<IScheduler> _taskPool = new Lazy<IScheduler>(static () => Initialize("TaskPool"));
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.
         /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs

@@ -68,7 +68,7 @@ namespace System.Reactive.Concurrency
 
 
             if (cancellationToken.CanBeCanceled)
             if (cancellationToken.CanBeCanceled)
             {
             {
-                _ctr = _cancellationToken.Register(@this => ((SchedulerOperationAwaiter)@this).Cancel(), this);
+                _ctr = _cancellationToken.Register(static @this => ((SchedulerOperationAwaiter)@this).Cancel(), this);
             }
             }
         }
         }
 
 
@@ -120,7 +120,7 @@ namespace System.Reactive.Concurrency
                         // is a conscious design decision as the performance impact was non
                         // is a conscious design decision as the performance impact was non
                         // negligible and our schedulers abstract over more constructs.
                         // negligible and our schedulers abstract over more constructs.
                         //
                         //
-                        ctx.Post(a => ((Action)a)(), original);
+                        ctx.Post(static a => ((Action)a)(), original);
                     };
                     };
                 }
                 }
             }
             }

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Concurrency/TaskPoolScheduler.cs

@@ -147,7 +147,7 @@ namespace System.Reactive.Concurrency
             public bool IsDisposed => Disposable.GetIsDisposed(ref _cancel);
             public bool IsDisposed => Disposable.GetIsDisposed(ref _cancel);
         }
         }
 
 
-        private static readonly Lazy<TaskPoolScheduler> LazyInstance = new Lazy<TaskPoolScheduler>(() => new TaskPoolScheduler(new TaskFactory(TaskScheduler.Default)));
+        private static readonly Lazy<TaskPoolScheduler> LazyInstance = new Lazy<TaskPoolScheduler>(static () => new TaskPoolScheduler(new TaskFactory(TaskScheduler.Default)));
         private readonly TaskFactory _taskFactory;
         private readonly TaskFactory _taskFactory;
 
 
         /// <summary>
         /// <summary>
@@ -294,7 +294,7 @@ namespace System.Reactive.Concurrency
             private void MoveNext()
             private void MoveNext()
             {
             {
                 TaskHelpers.Delay(_period, _cts.Token).ContinueWith(
                 TaskHelpers.Delay(_period, _cts.Token).ContinueWith(
-                    (_, thisObject) =>
+                    static (_, thisObject) =>
                     {
                     {
                         var @this = (PeriodicallyScheduledWorkItem<TState>)thisObject;
                         var @this = (PeriodicallyScheduledWorkItem<TState>)thisObject;
 
 
@@ -302,7 +302,7 @@ namespace System.Reactive.Concurrency
 
 
                         @this._gate.Wait(
                         @this._gate.Wait(
                             @this,
                             @this,
-                            closureThis => closureThis._state = closureThis._action(closureThis._state));
+                            static closureThis => closureThis._state = closureThis._action(closureThis._state));
                     },
                     },
                     this,
                     this,
                     CancellationToken.None,
                     CancellationToken.None,

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.Windows.cs

@@ -15,7 +15,7 @@ namespace System.Reactive.Concurrency
     [CLSCompliant(false)]
     [CLSCompliant(false)]
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerPeriodic
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerPeriodic
     {
     {
-        private static readonly Lazy<ThreadPoolScheduler> LazyDefault = new Lazy<ThreadPoolScheduler>(() => new ThreadPoolScheduler());
+        private static readonly Lazy<ThreadPoolScheduler> LazyDefault = new Lazy<ThreadPoolScheduler>(static () => new ThreadPoolScheduler());
 
 
         /// <summary>
         /// <summary>
         /// Constructs a ThreadPoolScheduler that schedules units of work on the Windows ThreadPool.
         /// Constructs a ThreadPoolScheduler that schedules units of work on the Windows ThreadPool.
@@ -177,7 +177,7 @@ namespace System.Reactive.Concurrency
             {
             {
                 _gate.Wait(
                 _gate.Wait(
                     this,
                     this,
-                    @this => @this._state = @this._action(@this._state));
+                    static @this => @this._state = @this._action(@this._state));
             }
             }
 
 
             public void Dispose()
             public void Dispose()

+ 7 - 7
Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs

@@ -14,8 +14,8 @@ namespace System.Reactive.Concurrency
     /// <seealso cref="Instance">Singleton instance of this type exposed through this static property.</seealso>
     /// <seealso cref="Instance">Singleton instance of this type exposed through this static property.</seealso>
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerLongRunning, ISchedulerPeriodic
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerLongRunning, ISchedulerPeriodic
     {
     {
-        private static readonly Lazy<ThreadPoolScheduler> LazyInstance = new Lazy<ThreadPoolScheduler>(() => new ThreadPoolScheduler());
-        private static readonly Lazy<NewThreadScheduler> LazyNewBackgroundThread = new Lazy<NewThreadScheduler>(() => new NewThreadScheduler(action => new Thread(action) { IsBackground = true }));
+        private static readonly Lazy<ThreadPoolScheduler> LazyInstance = new Lazy<ThreadPoolScheduler>(static () => new ThreadPoolScheduler());
+        private static readonly Lazy<NewThreadScheduler> LazyNewBackgroundThread = new Lazy<NewThreadScheduler>(static () => new NewThreadScheduler(action => new Thread(action) { IsBackground = true }));
 
 
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the CLR thread pool scheduler.
         /// Gets the singleton instance of the CLR thread pool scheduler.
@@ -44,7 +44,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
             var workItem = new UserWorkItem<TState>(this, state, action);
 
 
             ThreadPool.QueueUserWorkItem(
             ThreadPool.QueueUserWorkItem(
-                closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
                 workItem);
                 workItem);
 
 
             return workItem;
             return workItem;
@@ -75,7 +75,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
             var workItem = new UserWorkItem<TState>(this, state, action);
 
 
             workItem.CancelQueueDisposable = new Timer(
             workItem.CancelQueueDisposable = new Timer(
-                closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
                 workItem,
                 workItem,
                 dt,
                 dt,
                 Timeout.InfiniteTimeSpan);
                 Timeout.InfiniteTimeSpan);
@@ -156,7 +156,7 @@ namespace System.Reactive.Concurrency
                 _state = state;
                 _state = state;
                 _action = action;
                 _action = action;
 
 
-                ThreadPool.QueueUserWorkItem(_ => Tick(_), this);   // Replace with method group as soon as Roslyn will cache the delegate then.
+                ThreadPool.QueueUserWorkItem(static @this => Tick(@this), this);   // Replace with method group as soon as Roslyn will cache the delegate then.
             }
             }
 
 
             private static void Tick(object state)
             private static void Tick(object state)
@@ -166,7 +166,7 @@ namespace System.Reactive.Concurrency
                 if (!timer._disposed)
                 if (!timer._disposed)
                 {
                 {
                     timer._state = timer._action(timer._state);
                     timer._state = timer._action(timer._state);
-                    ThreadPool.QueueUserWorkItem(_ => Tick(_), timer);
+                    ThreadPool.QueueUserWorkItem(static t => Tick(t), timer);
                 }
                 }
             }
             }
 
 
@@ -196,7 +196,7 @@ namespace System.Reactive.Concurrency
                 // Rooting of the timer happens through the this.Tick delegate's target object,
                 // Rooting of the timer happens through the this.Tick delegate's target object,
                 // which is the current instance and has a field to store the Timer instance.
                 // which is the current instance and has a field to store the Timer instance.
                 //
                 //
-                _timer = new Timer(@this => ((PeriodicTimer<TState>)@this).Tick(), this, period, period);
+                _timer = new Timer(static @this => ((PeriodicTimer<TState>)@this).Tick(), this, period, period);
             }
             }
 
 
             private void Tick()
             private void Tick()

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs

@@ -38,7 +38,7 @@ namespace System.Reactive.Concurrency
             // an anonymous delegate will allow delegate caching.
             // an anonymous delegate will allow delegate caching.
             // Watch https://github.com/dotnet/roslyn/issues/5835 for compiler
             // Watch https://github.com/dotnet/roslyn/issues/5835 for compiler
             // support for caching delegates from method groups.
             // support for caching delegates from method groups.
-            return scheduler.ScheduleRelative(action, dueTime, (s, a) => Invoke(s, a));
+            return scheduler.ScheduleRelative(action, dueTime, static (s, a) => Invoke(s, a));
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -64,7 +64,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
             }
             }
 
 
-            return scheduler.ScheduleAbsolute(action, dueTime, (s, a) => Invoke(s, a));
+            return scheduler.ScheduleAbsolute(action, dueTime, static (s, a) => Invoke(s, a));
         }
         }
 
 
         private static IDisposable Invoke(IScheduler scheduler, Action action)
         private static IDisposable Invoke(IScheduler scheduler, Action action)

+ 10 - 6
Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs

@@ -332,20 +332,24 @@ namespace System.Reactive.Concurrency
         /// <returns>New stopwatch object; started at the time of the request.</returns>
         /// <returns>New stopwatch object; started at the time of the request.</returns>
         public IStopwatch StartStopwatch()
         public IStopwatch StartStopwatch()
         {
         {
-            var start = ToDateTimeOffset(Clock);
-            return new VirtualTimeStopwatch(() => ToDateTimeOffset(Clock) - start);
+            var start = ClockToDateTimeOffset();
+            return new VirtualTimeStopwatch(this, start);
         }
         }
 
 
+        private DateTimeOffset ClockToDateTimeOffset() => ToDateTimeOffset(Clock);
+
         private sealed class VirtualTimeStopwatch : IStopwatch
         private sealed class VirtualTimeStopwatch : IStopwatch
         {
         {
-            private readonly Func<TimeSpan> _getElapsed;
+            private readonly VirtualTimeSchedulerBase<TAbsolute, TRelative> _parent;
+            private readonly DateTimeOffset _start;
 
 
-            public VirtualTimeStopwatch(Func<TimeSpan> getElapsed)
+            public VirtualTimeStopwatch(VirtualTimeSchedulerBase<TAbsolute, TRelative> parent, DateTimeOffset start)
             {
             {
-                _getElapsed = getElapsed;
+                _parent = parent;
+                _start = start;
             }
             }
 
 
-            public TimeSpan Elapsed => _getElapsed();
+            public TimeSpan Elapsed => _parent.ClockToDateTimeOffset() - _start;
         }
         }
     }
     }
 
 

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Disposables/ContextDisposable.cs

@@ -46,7 +46,7 @@ namespace System.Reactive.Disposables
         /// </summary>
         /// </summary>
         public void Dispose()
         public void Dispose()
         {
         {
-            Disposable.TryRelease(ref _disposable, Context, (disposable, context) => context.PostWithStartComplete(d => d.Dispose(), disposable));
+            Disposable.TryRelease(ref _disposable, Context, static (disposable, context) => context.PostWithStartComplete(static d => d.Dispose(), disposable));
         }
         }
     }
     }
 }
 }

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Internal/AsyncLockObserver.cs

@@ -21,21 +21,21 @@ namespace System.Reactive
         {
         {
             _gate.Wait(
             _gate.Wait(
                 (_observer, value),
                 (_observer, value),
-                tuple => tuple._observer.OnNext(tuple.value));
+                static tuple => tuple._observer.OnNext(tuple.value));
         }
         }
 
 
         protected override void OnErrorCore(Exception exception)
         protected override void OnErrorCore(Exception exception)
         {
         {
             _gate.Wait(
             _gate.Wait(
                 (_observer, exception),
                 (_observer, exception),
-                tuple => tuple._observer.OnError(tuple.exception));
+                static tuple => tuple._observer.OnError(tuple.exception));
         }
         }
 
 
         protected override void OnCompletedCore()
         protected override void OnCompletedCore()
         {
         {
             _gate.Wait(
             _gate.Wait(
                 _observer,
                 _observer,
-                closureObserver => closureObserver.OnCompleted());
+                static closureObserver => closureObserver.OnCompleted());
         }
         }
     }
     }
 }
 }

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Internal/Producer.cs

@@ -57,7 +57,7 @@ namespace System.Reactive
 
 
                 CurrentThreadScheduler.Instance.ScheduleAction(
                 CurrentThreadScheduler.Instance.ScheduleAction(
                     (@this: this, runAssignable, observer),
                     (@this: this, runAssignable, observer),
-                    tuple => tuple.runAssignable.Disposable = [email protected](tuple.observer));
+                    static tuple => tuple.runAssignable.Disposable = [email protected](tuple.observer));
 
 
                 run = runAssignable;
                 run = runAssignable;
             }
             }
@@ -118,7 +118,7 @@ namespace System.Reactive
             {
             {
                 CurrentThreadScheduler.Instance.ScheduleAction(
                 CurrentThreadScheduler.Instance.ScheduleAction(
                     (@this: this, sink),
                     (@this: this, sink),
-                    tuple => [email protected](tuple.sink));
+                    static tuple => [email protected](tuple.sink));
             }
             }
             else
             else
             {
             {

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs

@@ -494,7 +494,7 @@ namespace System.Reactive
         /// whenever the signals have to be drained.
         /// whenever the signals have to be drained.
         /// </summary>
         /// </summary>
         private static readonly Func<IScheduler, ObserveOnObserverNew<T>, IDisposable> DrainShortRunningFunc =
         private static readonly Func<IScheduler, ObserveOnObserverNew<T>, IDisposable> DrainShortRunningFunc =
-            (scheduler, self) => self.DrainShortRunning(scheduler);
+            static (scheduler, self) => self.DrainShortRunning(scheduler);
 
 
         /// <summary>
         /// <summary>
         /// Emits at most one signal per run on a scheduler that doesn't like
         /// Emits at most one signal per run on a scheduler that doesn't like
@@ -682,7 +682,7 @@ namespace System.Reactive
         /// <summary>
         /// <summary>
         /// Static reference to the Drain method, saves allocation.
         /// Static reference to the Drain method, saves allocation.
         /// </summary>
         /// </summary>
-        private static readonly Action<ObserveOnObserverLongRunning<TSource>, ICancelable> DrainLongRunning = (self, cancelable) => self.Drain();
+        private static readonly Action<ObserveOnObserverLongRunning<TSource>, ICancelable> DrainLongRunning = static (self, cancelable) => self.Drain();
 
 
         protected override void Dispose(bool disposing)
         protected override void Dispose(bool disposing)
         {
         {

+ 6 - 6
Rx.NET/Source/src/System.Reactive/Internal/Stubs.cs

@@ -6,23 +6,23 @@ namespace System.Reactive
 {
 {
     internal static class Stubs<T>
     internal static class Stubs<T>
     {
     {
-        public static readonly Action<T> Ignore = _ => { };
-        public static readonly Func<T, T> I = _ => _;
+        public static readonly Action<T> Ignore = static _ => { };
+        public static readonly Func<T, T> I = static _ => _;
     }
     }
 
 
     internal static class Stubs
     internal static class Stubs
     {
     {
-        public static readonly Action Nop = () => { };
-        public static readonly Action<Exception> Throw = ex => { ex.Throw(); };
+        public static readonly Action Nop = static () => { };
+        public static readonly Action<Exception> Throw = static ex => { ex.Throw(); };
     }
     }
 
 
 #if !NO_THREAD
 #if !NO_THREAD
     internal static class TimerStubs
     internal static class TimerStubs
     {
     {
 #if NETSTANDARD1_3
 #if NETSTANDARD1_3
-        public static readonly System.Threading.Timer Never = new System.Threading.Timer(_ => { }, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
+        public static readonly System.Threading.Timer Never = new System.Threading.Timer(static _ => { }, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
 #else
 #else
-        public static readonly System.Threading.Timer Never = new System.Threading.Timer(_ => { });
+        public static readonly System.Threading.Timer Never = new System.Threading.Timer(static _ => { });
 #endif
 #endif
     }
     }
 #endif
 #endif

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs

@@ -126,7 +126,7 @@ namespace System.Reactive.Concurrency
                     if (t != null)
                     if (t != null)
                     {
                     {
                         t.Stop();
                         t.Stop();
-                        action = (_, __) => Disposable.Empty;
+                        action = static (_, __) => Disposable.Empty;
                     }
                     }
                 });
                 });
 
 
@@ -193,7 +193,7 @@ namespace System.Reactive.Concurrency
                     if (t != null)
                     if (t != null)
                     {
                     {
                         t.Stop();
                         t.Stop();
-                        action = _ => _;
+                        action = static _ => _;
                     }
                     }
                 });
                 });
             });
             });

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/DispatcherScheduler.cs

@@ -161,7 +161,7 @@ namespace System.Reactive.Concurrency
                 if (t != null)
                 if (t != null)
                 {
                 {
                     t.Stop();
                     t.Stop();
-                    action = (_, __) => Disposable.Empty;
+                    action = static (_, __) => Disposable.Empty;
                 }
                 }
             });
             });
 
 
@@ -208,7 +208,7 @@ namespace System.Reactive.Concurrency
                 if (t != null)
                 if (t != null)
                 {
                 {
                     t.Stop();
                     t.Stop();
-                    action = _ => _;
+                    action = static _ => _;
                 }
                 }
             });
             });
         }
         }

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Concurrency/CoreDispatcherScheduler.cs

@@ -213,7 +213,7 @@ namespace System.Reactive.Concurrency
                 if (t != null)
                 if (t != null)
                 {
                 {
                     t.Stop();
                     t.Stop();
-                    action = (_, __) => Disposable.Empty;
+                    action = static (_, __) => Disposable.Empty;
                 }
                 }
             });
             });
 
 
@@ -264,7 +264,7 @@ namespace System.Reactive.Concurrency
                 if (t != null)
                 if (t != null)
                 {
                 {
                     t.Stop();
                     t.Stop();
-                    action = _ => _;
+                    action = static _ => _;
                 }
                 }
             });
             });
         }
         }

+ 9 - 9
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Foundation/AsyncInfoExtensions.cs

@@ -32,7 +32,7 @@ namespace System.Reactive.Windows.Foundation
 
 
             return new AsyncInfoToObservableBridge<Unit, Unit>(
             return new AsyncInfoToObservableBridge<Unit, Unit>(
                 source,
                 source,
-                (iai, a) => ((IAsyncAction)iai).Completed += new AsyncActionCompletedHandler((iaa, status) => a(iaa, status)),
+                static (iai, a) => ((IAsyncAction)iai).Completed += new AsyncActionCompletedHandler((iaa, status) => a(iaa, status)),
                 iai => Unit.Default,
                 iai => Unit.Default,
                 onProgress: null,
                 onProgress: null,
                 progress: null,
                 progress: null,
@@ -101,7 +101,7 @@ namespace System.Reactive.Windows.Foundation
             {
             {
                 var progress = observer.ToProgress();
                 var progress = observer.ToProgress();
                 var src = source.ToObservable_(progress);
                 var src = source.ToObservable_(progress);
-                return src.Subscribe(_ => { }, observer.OnError, observer.OnCompleted);
+                return src.Subscribe(static _ => { }, observer.OnError, observer.OnCompleted);
             });
             });
         }
         }
 
 
@@ -109,9 +109,9 @@ namespace System.Reactive.Windows.Foundation
         {
         {
             return new AsyncInfoToObservableBridge<Unit, TProgress>(
             return new AsyncInfoToObservableBridge<Unit, TProgress>(
                 source,
                 source,
-                (iai, a) => ((IAsyncActionWithProgress<TProgress>)iai).Completed += new AsyncActionWithProgressCompletedHandler<TProgress>((iaa, status) => a(iaa, status)),
+                static (iai, a) => ((IAsyncActionWithProgress<TProgress>)iai).Completed += new AsyncActionWithProgressCompletedHandler<TProgress>((iaa, status) => a(iaa, status)),
                 iai => Unit.Default,
                 iai => Unit.Default,
-                (iai, a) => ((IAsyncActionWithProgress<TProgress>)iai).Progress += new AsyncActionProgressHandler<TProgress>((iap, p) => a(iap, p)),
+                static (iai, a) => ((IAsyncActionWithProgress<TProgress>)iai).Progress += new AsyncActionProgressHandler<TProgress>((iap, p) => a(iap, p)),
                 progress,
                 progress,
                 multiValue: false
                 multiValue: false
             );
             );
@@ -138,8 +138,8 @@ namespace System.Reactive.Windows.Foundation
 
 
             return new AsyncInfoToObservableBridge<TResult, Unit>(
             return new AsyncInfoToObservableBridge<TResult, Unit>(
                 source,
                 source,
-                (iai, a) => ((IAsyncOperation<TResult>)iai).Completed += new AsyncOperationCompletedHandler<TResult>((iao, status) => a(iao, status)),
-                iai => ((IAsyncOperation<TResult>)iai).GetResults(),
+                static (iai, a) => ((IAsyncOperation<TResult>)iai).Completed += new AsyncOperationCompletedHandler<TResult>((iao, status) => a(iao, status)),
+                static iai => ((IAsyncOperation<TResult>)iai).GetResults(),
                 onProgress: null,
                 onProgress: null,
                 progress: null,
                 progress: null,
                 multiValue: false
                 multiValue: false
@@ -210,7 +210,7 @@ namespace System.Reactive.Windows.Foundation
             {
             {
                 var progress = observer.ToProgress();
                 var progress = observer.ToProgress();
                 var src = source.ToObservable_(progress, false);
                 var src = source.ToObservable_(progress, false);
-                return src.Subscribe(_ => { }, observer.OnError, observer.OnCompleted);
+                return src.Subscribe(static _ => { }, observer.OnError, observer.OnCompleted);
             });
             });
         }
         }
 
 
@@ -264,9 +264,9 @@ namespace System.Reactive.Windows.Foundation
         {
         {
             return new AsyncInfoToObservableBridge<TResult, TProgress>(
             return new AsyncInfoToObservableBridge<TResult, TProgress>(
                 source,
                 source,
-                (iai, a) => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).Completed += new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>((iao, status) => a(iao, status)),
+                static (iai, a) => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).Completed += new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>((iao, status) => a(iao, status)),
                 iai => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).GetResults(),
                 iai => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).GetResults(),
-                (iai, a) => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).Progress += new AsyncOperationProgressHandler<TResult, TProgress>((iap, p) => a(iap, p)),
+                static (iai, a) => ((IAsyncOperationWithProgress<TResult, TProgress>)iai).Progress += new AsyncOperationProgressHandler<TResult, TProgress>((iap, p) => a(iap, p)),
                 progress,
                 progress,
                 supportsMultiple
                 supportsMultiple
             );
             );

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/CoreDispatcherObservable.cs

@@ -152,7 +152,7 @@ namespace System.Reactive.Linq
 
 
 #endregion
 #endregion
 
 
-#region SubscribeOn[Dispatcher]
+        #region SubscribeOn[Dispatcher]
 
 
         /// <summary>
         /// <summary>
         /// Wraps the source sequence in order to run its subscription and unsubscription logic on the specified dispatcher.
         /// Wraps the source sequence in order to run its subscription and unsubscription logic on the specified dispatcher.
@@ -309,7 +309,7 @@ namespace System.Reactive.Linq
             return Synchronization.SubscribeOn(source, new CoreDispatcherScheduler(CoreDispatcherScheduler.Current.Dispatcher, priority));
             return Synchronization.SubscribeOn(source, new CoreDispatcherScheduler(CoreDispatcherScheduler.Current.Dispatcher, priority));
         }
         }
 
 
-#endregion
+        #endregion
     }
     }
 }
 }
 #endif
 #endif

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Platforms/UWP/Linq/WindowsObservable.Events.cs

@@ -111,7 +111,7 @@ namespace System.Reactive.Linq
                 throw new ArgumentNullException(nameof(source));
                 throw new ArgumentNullException(nameof(source));
             }
             }
 
 
-            return new EventPatternSource<TSender, TEventArgs>(source, (h, evt) => h(evt.Sender, evt.EventArgs));
+            return new EventPatternSource<TSender, TEventArgs>(source, static (h, evt) => h(evt.Sender, evt.EventArgs));
         }
         }
     }
     }
 }
 }

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Platforms/Windows/ThreadPoolTimerExtensions.cs

@@ -13,12 +13,12 @@ namespace System.Reactive.Concurrency
     {
     {
         public static IDisposable AsDisposable(this ThreadPoolTimer threadPoolTimer)
         public static IDisposable AsDisposable(this ThreadPoolTimer threadPoolTimer)
         {
         {
-            return Disposable.Create(threadPoolTimer, _ => _.Cancel());
+            return Disposable.Create(threadPoolTimer, static _ => _.Cancel());
         }
         }
 
 
         public static IDisposable AsDisposable(this IAsyncInfo asyncInfo)
         public static IDisposable AsDisposable(this IAsyncInfo asyncInfo)
         {
         {
-            return Disposable.Create(asyncInfo, _ => _.Cancel());
+            return Disposable.Create(asyncInfo, static _ => _.Cancel());
         }
         }
     }
     }
 }
 }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs

@@ -405,7 +405,7 @@ namespace System.Reactive.Subjects
                     // Task objects or the async method builder's interaction with the
                     // Task objects or the async method builder's interaction with the
                     // SynchronizationContext object.
                     // SynchronizationContext object.
                     //
                     //
-                    _context.Post(c => ((Action)c)(), _callback);
+                    _context.Post(static c => ((Action)c)(), _callback);
                 }
                 }
                 else
                 else
                 {
                 {

+ 32 - 25
Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs

@@ -38,13 +38,15 @@ namespace System.Reactive.Threading.Tasks
                 var options = GetTaskContinuationOptions(_scheduler);
                 var options = GetTaskContinuationOptions(_scheduler);
 
 
                 if (_scheduler == null)
                 if (_scheduler == null)
-                    _task.ContinueWith((t, subjectObject) => t.EmitTaskResult((IObserver<Unit>)subjectObject), observer, cts.Token, options, TaskScheduler.Current);
+                {
+                    _task.ContinueWith(static (t, subjectObject) => t.EmitTaskResult((IObserver<Unit>)subjectObject), observer, cts.Token, options, TaskScheduler.Current);
+                }
                 else
                 else
                 {
                 {
                     _task.ContinueWithState(
                     _task.ContinueWithState(
-                        (task, tuple) => tuple.@this._scheduler.ScheduleAction(
+                        static (task, tuple) => tuple.@this._scheduler.ScheduleAction(
                             (task, tuple.observer),
                             (task, tuple.observer),
-                            tuple2 => tuple2.task.EmitTaskResult(tuple2.observer)),
+                            static tuple2 => tuple2.task.EmitTaskResult(tuple2.observer)),
                         (@this: this, observer),
                         (@this: this, observer),
                         cts.Token,
                         cts.Token,
                         options);
                         options);
@@ -77,14 +79,14 @@ namespace System.Reactive.Threading.Tasks
 
 
                 if (_scheduler == null)
                 if (_scheduler == null)
                 {
                 {
-                    _task.ContinueWith((t, subjectObject) => t.EmitTaskResult((IObserver<TResult>)subjectObject), observer, cts.Token, options, TaskScheduler.Current);
+                    _task.ContinueWith(static (t, subjectObject) => t.EmitTaskResult((IObserver<TResult>)subjectObject), observer, cts.Token, options, TaskScheduler.Current);
                 }
                 }
                 else
                 else
                 {
                 {
                     _task.ContinueWithState(
                     _task.ContinueWithState(
-                        (task, tuple) => tuple.@this._scheduler.ScheduleAction(
+                        static (task, tuple) => tuple.@this._scheduler.ScheduleAction(
                             (task, tuple.observer),
                             (task, tuple.observer),
-                            tuple2 => tuple2.task.EmitTaskResult(tuple2.observer)),
+                            static tuple2 => tuple2.task.EmitTaskResult(tuple2.observer)),
                         (@this: this, observer),
                         (@this: this, observer),
                         cts.Token,
                         cts.Token,
                         options);
                         options);
@@ -178,7 +180,7 @@ namespace System.Reactive.Threading.Tasks
             var cts = new CancellationDisposable();
             var cts = new CancellationDisposable();
 
 
             task.ContinueWith(
             task.ContinueWith(
-                (t, observerObject) => t.EmitTaskResult((IObserver<Unit>)observerObject), 
+                static (t, observerObject) => t.EmitTaskResult((IObserver<Unit>)observerObject), 
                 observer, 
                 observer, 
                 cts.Token, 
                 cts.Token, 
                 TaskContinuationOptions.ExecuteSynchronously, 
                 TaskContinuationOptions.ExecuteSynchronously, 
@@ -296,7 +298,7 @@ namespace System.Reactive.Threading.Tasks
             var cts = new CancellationDisposable();
             var cts = new CancellationDisposable();
 
 
             task.ContinueWith(
             task.ContinueWith(
-                (t, observerObject) => t.EmitTaskResult((IObserver<TResult>)observerObject), 
+                static (t, observerObject) => t.EmitTaskResult((IObserver<TResult>)observerObject), 
                 observer, 
                 observer, 
                 cts.Token, 
                 cts.Token, 
                 TaskContinuationOptions.ExecuteSynchronously, 
                 TaskContinuationOptions.ExecuteSynchronously, 
@@ -407,24 +409,29 @@ namespace System.Reactive.Threading.Tasks
                 throw new ArgumentNullException(nameof(scheduler));
                 throw new ArgumentNullException(nameof(scheduler));
             }
             }
             var tcs = new TaskCompletionSource<TResult>(task.AsyncState);
             var tcs = new TaskCompletionSource<TResult>(task.AsyncState);
-            task.ContinueWith(t =>
-            {
-                scheduler.Schedule(() =>
+            task.ContinueWith(
+                static (t, o) =>
                 {
                 {
-                    if (t.IsCanceled)
-                    {
-                        tcs.TrySetCanceled(new TaskCanceledException(t).CancellationToken);
-                    }
-                    else if (t.IsFaulted)
-                    {
-                        tcs.TrySetException(t.Exception.InnerExceptions);
-                    }
-                    else
+                    var (scheduler, tcs) = ((IScheduler, TaskCompletionSource<TResult>))o;
+
+                    scheduler.ScheduleAction((t, tcs), static state =>
                     {
                     {
-                        tcs.TrySetResult(t.Result);
-                    }
-                });
-            }, TaskContinuationOptions.ExecuteSynchronously);
+                        if (state.t.IsCanceled)
+                        {
+                            state.tcs.TrySetCanceled(new TaskCanceledException(state.t).CancellationToken);
+                        }
+                        else if (state.t.IsFaulted)
+                        {
+                            state.tcs.TrySetException(state.t.Exception.InnerExceptions);
+                        }
+                        else
+                        {
+                            state.tcs.TrySetResult(state.t.Result);
+                        }
+                    });
+                },
+                (scheduler, tcs),
+                TaskContinuationOptions.ExecuteSynchronously);
             return tcs.Task;
             return tcs.Task;
         }
         }
 
 
@@ -444,7 +451,7 @@ namespace System.Reactive.Threading.Tasks
 
 
                 if (ct.CanBeCanceled)
                 if (ct.CanBeCanceled)
                 {
                 {
-                    _ctr = ct.Register(@this => ((ToTaskObserver<TResult>)@this).Cancel(), this);
+                    _ctr = ct.Register(static @this => ((ToTaskObserver<TResult>)@this).Cancel(), this);
                 }
                 }
             }
             }
 
 

二進制
Rx.NET/Source/tests/Tests.System.Reactive.Uwp.DeviceRunner/AppPackages/Tests.System.Reactive.Uwp.DeviceRunner_1.0.0.0_x86_Debug_Test/Tests.System.Reactive.Uwp.DeviceRunner_1.0.0.0_x86_Debug.appx