@@ -376,11 +376,20 @@ public void SetJobMemoryLimit(long process_memory_limit)
376376 /// <summary>
377377 /// Set the time limit for a process.
378378 /// </summary>
379- /// <param name="process_time_limit">The time limit for a process, in 100ns ticks.</param>
379+ /// <param name="process_time_limit">The time limit for a process, in 100ns ticks. Set to 0 to clear the timeout. </param>
380380 /// <param name="throw_on_error">True to throw on error.</param>
381381 /// <returns>The NT status code.</returns>
382382 public NtStatus SetProcessTimeLimit ( long process_time_limit , bool throw_on_error )
383383 {
384+ if ( process_time_limit == 0 )
385+ {
386+ return SetExtendedLimitInformation ( i => {
387+ i . BasicLimitInformation . PerProcessUserTimeLimit = new LargeIntegerStruct ( ) ;
388+ i . BasicLimitInformation . LimitFlags &= ~ JobObjectLimitFlags . ProcessTime ;
389+ return i ;
390+ } , throw_on_error ) ;
391+ }
392+
384393 return SetExtendedLimitInformation ( i => {
385394 i . BasicLimitInformation . PerProcessUserTimeLimit = new LargeIntegerStruct ( ) { QuadPart = process_time_limit } ;
386395 i . BasicLimitInformation . LimitFlags |= JobObjectLimitFlags . ProcessTime ;
@@ -391,20 +400,49 @@ public NtStatus SetProcessTimeLimit(long process_time_limit, bool throw_on_error
391400 /// <summary>
392401 /// Set the time limit for a process.
393402 /// </summary>
394- /// <param name="process_time_limit">The time limit for a process, in 100ns ticks.</param>
403+ /// <param name="process_time_limit">The time limit for a process, in 100ns ticks. Set to 0 to clear the timeout. </param>
395404 public void SetProcessTimeLimit ( long process_time_limit )
396405 {
397406 SetProcessTimeLimit ( process_time_limit , true ) ;
398407 }
399408
409+ /// <summary>
410+ /// Set the time limit for a process.
411+ /// </summary>
412+ /// <param name="process_time_limit">The time limit for a process.</param>
413+ /// <param name="throw_on_error">True to throw on error.</param>
414+ /// <returns>The NT status code.</returns>
415+ public NtStatus SetProcessTimeLimit ( NtWaitTimeout process_time_limit , bool throw_on_error )
416+ {
417+ return SetProcessTimeLimit ( Math . Abs ( process_time_limit ? . Timeout ? . QuadPart ?? 0 ) , throw_on_error ) ;
418+ }
419+
420+ /// <summary>
421+ /// Set the time limit for a process.
422+ /// </summary>
423+ /// <param name="process_time_limit">The time limit for a process.</param>
424+ public void SetProcessTimeLimit ( NtWaitTimeout process_time_limit )
425+ {
426+ SetProcessTimeLimit ( process_time_limit , true ) ;
427+ }
428+
400429 /// <summary>
401430 /// Set the time limit for a job.
402431 /// </summary>
403- /// <param name="job_time_limit">The time limit for a job, in 100ns ticks.</param>
432+ /// <param name="job_time_limit">The time limit for a job, in 100ns ticks. Set to 0 to clear timeout. </param>
404433 /// <param name="throw_on_error">True to throw on error.</param>
405434 /// <returns>The NT status code.</returns>
406435 public NtStatus SetJobTimeLimit ( long job_time_limit , bool throw_on_error )
407436 {
437+ if ( job_time_limit == 0 )
438+ {
439+ return SetExtendedLimitInformation ( i => {
440+ i . BasicLimitInformation . PerJobUserTimeLimit = new LargeIntegerStruct ( ) { QuadPart = 0 } ;
441+ i . BasicLimitInformation . LimitFlags &= ~ JobObjectLimitFlags . JobTime ;
442+ return i ;
443+ } , throw_on_error ) ;
444+ }
445+
408446 return SetExtendedLimitInformation ( i => {
409447 i . BasicLimitInformation . PerJobUserTimeLimit = new LargeIntegerStruct ( ) { QuadPart = job_time_limit } ;
410448 i . BasicLimitInformation . LimitFlags |= JobObjectLimitFlags . JobTime ;
@@ -415,12 +453,32 @@ public NtStatus SetJobTimeLimit(long job_time_limit, bool throw_on_error)
415453 /// <summary>
416454 /// Set the time limit for a job.
417455 /// </summary>
418- /// <param name="job_time_limit">The time limit for a job, in 100ns ticks.</param>
456+ /// <param name="job_time_limit">The time limit for a job, in 100ns ticks. Set to 0 to clear timeout. </param>
419457 public void SetJobTimeLimit ( long job_time_limit )
420458 {
421459 SetProcessTimeLimit ( job_time_limit , true ) ;
422460 }
423461
462+ /// <summary>
463+ /// Set the time limit for a job.
464+ /// </summary>
465+ /// <param name="job_time_limit">The time limit for a job.</param>
466+ /// <param name="throw_on_error">True to throw on error.</param>
467+ /// <returns>The NT status code.</returns>
468+ public NtStatus SetJobTimeLimit ( NtWaitTimeout job_time_limit , bool throw_on_error )
469+ {
470+ return SetJobMemoryLimit ( Math . Abs ( job_time_limit ? . Timeout ? . QuadPart ?? 0 ) , throw_on_error ) ;
471+ }
472+
473+ /// <summary>
474+ /// Set the time limit for a job.
475+ /// </summary>
476+ /// <param name="job_time_limit">The time limit for a job.</param>
477+ public void SetJobTimeLimit ( NtWaitTimeout job_time_limit )
478+ {
479+ SetJobTimeLimit ( job_time_limit , true ) ;
480+ }
481+
424482 /// <summary>
425483 /// Get list of process IDs in Job.
426484 /// </summary>
0 commit comments