@@ -73,20 +73,16 @@ public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TSta
73
73
if ( action == null )
74
74
throw new ArgumentNullException ( nameof ( action ) ) ;
75
75
76
- var d = new SingleAssignmentDisposable ( ) ;
76
+ var userWorkItem = new UserWorkItem < TState > ( this , state , action ) ;
77
+
78
+ var res = global ::Windows . System . Threading . ThreadPool . RunAsync (
79
+ iaa => userWorkItem . Run ( ) ,
80
+ Priority ,
81
+ Options ) ;
77
82
78
- var res = global ::Windows . System . Threading . ThreadPool . RunAsync ( iaa =>
79
- {
80
- if ( ! d . IsDisposed )
81
- {
82
- d . Disposable = action ( this , state ) ;
83
- }
84
- } , Priority , Options ) ;
85
-
86
- return new CompositeDisposable (
87
- d ,
88
- Disposable . Create ( res . Cancel )
89
- ) ;
83
+ userWorkItem . CancelQueueDisposable = Disposable . Create ( res . Cancel ) ;
84
+
85
+ return userWorkItem ;
90
86
}
91
87
92
88
/// <summary>
@@ -115,23 +111,15 @@ public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Fun
115
111
116
112
private IDisposable ScheduleSlow < TState > ( TState state , TimeSpan dueTime , Func < IScheduler , TState , IDisposable > action )
117
113
{
118
- var d = new SingleAssignmentDisposable ( ) ;
114
+ var userWorkItem = new UserWorkItem < TState > ( this , state , action ) ;
119
115
120
116
var res = global ::Windows . System . Threading . ThreadPoolTimer . CreateTimer (
121
- tpt =>
122
- {
123
- if ( ! d . IsDisposed )
124
- {
125
- d . Disposable = action ( this , state ) ;
126
- }
127
- } ,
128
- dueTime
129
- ) ;
130
-
131
- return new CompositeDisposable (
132
- d ,
133
- Disposable . Create ( res . Cancel )
134
- ) ;
117
+ tpt => userWorkItem . Run ( ) ,
118
+ dueTime ) ;
119
+
120
+ userWorkItem . CancelQueueDisposable = Disposable . Create ( res . Cancel ) ;
121
+
122
+ return userWorkItem ;
135
123
}
136
124
137
125
/// <summary>
0 commit comments