@@ -64,6 +64,16 @@ public static async Task Main(string[] args)
64
64
65
65
// Set up signal handler to Dispose the DDS entities
66
66
var cancellationSource = new CancellationTokenSource ( ) ;
67
+ var timeoutTask = Task . Delay ( TimeSpan . FromSeconds ( arguments . Timeout ) , cancellationSource . Token )
68
+ . ContinueWith ( _ =>
69
+ {
70
+ if ( ! cancellationSource . IsCancellationRequested )
71
+ {
72
+ Console . WriteLine ( "Shutting down due to timeout..." ) ;
73
+ cancellationSource . Cancel ( ) ;
74
+ }
75
+ } , TaskScheduler . Default ) ;
76
+
67
77
Console . CancelKeyPress += ( _ , eventArgs ) =>
68
78
{
69
79
Console . WriteLine ( "Shutting down..." ) ;
@@ -100,6 +110,7 @@ private class Arguments
100
110
public int Domain { get ; set ; }
101
111
public int N { get ; set ; } = int . MaxValue ;
102
112
public int PrimesPerReply { get ; set ; }
113
+ public int Timeout { get ; set ; }
103
114
}
104
115
105
116
// Uses the System.CommandLine package to parse the program arguments.
@@ -124,7 +135,11 @@ private static Arguments ParseArguments(string[] args)
124
135
description : "The number to calculate primes up to (only applicable with --requester)" ) ,
125
136
new System . CommandLine . Option < int > (
126
137
new string [ ] { "--primes-per-reply" , "-p" } ,
127
- getDefaultValue : ( ) => 5 )
138
+ getDefaultValue : ( ) => 5 ) ,
139
+ new System . CommandLine . Option < int > (
140
+ new string [ ] { "--timeout" } ,
141
+ getDefaultValue : ( ) => 120 ,
142
+ description : "Timeout in seconds to wait for the application to finish" )
128
143
} ;
129
144
130
145
rootCommand . Description = "Example RTI Connext Requester and Replier" ;
0 commit comments