11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . Linq ;
45using System . Reflection ;
56using System . Threading . Tasks ;
@@ -199,8 +200,11 @@ private void InitializeJob(ICrontabSchedulerJob job)
199200 _jobs . Add ( job ) ;
200201 }
201202
202- private void OnCronTimerTick ( object state )
203+ private void OnCronTimerTick ( object ? state )
203204 {
205+ if ( state is null )
206+ throw new ArgumentNullException ( nameof ( state ) ) ;
207+
204208 var job = ( ICrontabSchedulerJob ) state ;
205209
206210 if ( job . CrontabProcessor == null )
@@ -214,8 +218,11 @@ private void OnCronTimerTick(object state)
214218 OnStartWork ( state ) ;
215219 }
216220
217- private void OnStartWork ( object state )
221+ private void OnStartWork ( object ? state )
218222 {
223+ if ( state is null )
224+ throw new ArgumentNullException ( nameof ( state ) ) ;
225+
219226 var job = ( ICrontabSchedulerJob ) state ;
220227
221228 lock ( _workingJobsTasks )
@@ -232,8 +239,11 @@ private void OnStartWork(object state)
232239
233240 #region Execution
234241
235- private async Task Run ( object state )
242+ private async Task Run ( object ? state )
236243 {
244+ if ( state is null )
245+ throw new ArgumentNullException ( nameof ( state ) ) ;
246+
237247 var ( jobTaskID , job ) = ( Tuple < long , ICrontabSchedulerJob > ) state ;
238248
239249 try
@@ -291,26 +301,13 @@ private async Task RunBasicJob(ISchedulerJobRepresentation job)
291301
292302 private Task InvokeJobMethod ( ISchedulerJobRepresentation job , object jobObject )
293303 {
294- object result ;
295-
296- switch ( job . InvokeMethodParameterType )
304+ var result = job . InvokeMethodParameterType switch
297305 {
298- case InvokeMethodParameterType . Parameterless :
299- result = job . InvokeMethodInfo . Invoke ( jobObject , null ) ;
300- break ;
301-
302- case InvokeMethodParameterType . AppName :
303- result = job . InvokeMethodInfo . Invoke ( jobObject , new object [ ] { AppName } ) ;
304- break ;
305-
306- case InvokeMethodParameterType . Args :
307- result = job . InvokeMethodInfo . Invoke ( jobObject , new object [ ] { job . JobArgs } ) ;
308- break ;
309-
310- default :
311- throw new ArgumentOutOfRangeException ( ) ;
312- }
313-
306+ InvokeMethodParameterType . Parameterless => job . InvokeMethodInfo . Invoke ( jobObject , null ) ,
307+ InvokeMethodParameterType . AppName => job . InvokeMethodInfo . Invoke ( jobObject , new object [ ] { AppName } ) ,
308+ InvokeMethodParameterType . Args => job . InvokeMethodInfo . Invoke ( jobObject , new object [ ] { job . JobArgs } ) ,
309+ _ => throw new InvalidEnumArgumentException ( nameof ( job . InvokeMethodParameterType ) ) ,
310+ } ;
314311 if ( result is Task task )
315312 return task ;
316313
0 commit comments