File tree Expand file tree Collapse file tree 2 files changed +22
-16
lines changed
examples/Smdn.Net.MuninNode Expand file tree Collapse file tree 2 files changed +22
-16
lines changed Original file line number Diff line number Diff line change 7171 args . Cancel = true ;
7272} ;
7373
74- // Start node and accept connections.
75- node . Start ( ) ;
76-
77- await node . AcceptAsync ( throwIfCancellationRequested : false , cts . Token ) ;
78-
79- // When the AcceptAsync method finishes processing one connection,
74+ // Start the node and accept connections.
75+ //
76+ // When the RunAsync method finishes processing one connection,
8077// it immediately waits for the next connection.
8178// Therefore, the method will not return until the cancellation is
8279// requested by CancellationToken.
83- //
84- // By specifying false to the throwIfCancellationRequested, you can
85- // let the AcceptAsync method to return without throwing
86- // OperationCanceledException when a cancellation is requested.
80+ try {
81+ await node . RunAsync ( cts . Token ) ;
82+ }
83+ catch ( OperationCanceledException ex ) when ( ex . CancellationToken == cts . Token ) {
84+ // CancellationToken is triggered
85+ Console . WriteLine ( "stopped" ) ;
86+ }
8787
88- Console . WriteLine ( "stopped" ) ;
88+ // Instead of RunAsync(), StartAsync() and AcceptAsync() can be called
89+ // separately to start the node.
90+ //
91+ // await node.StartAsync(cts.Token);
92+ // await node.AcceptAsync(throwIfCancellationRequested: false, cts.Token);
93+ // Console.WriteLine("stopped");
Original file line number Diff line number Diff line change 5959 args . Cancel = true ;
6060} ;
6161
62- node . Start ( ) ;
63-
64- await node . AcceptAsync ( throwIfCancellationRequested : false , cts . Token ) ;
65-
66- Console . WriteLine ( "stopped" ) ;
62+ try {
63+ await node . RunAsync ( cts . Token ) ;
64+ }
65+ catch ( OperationCanceledException ex ) when ( ex . CancellationToken == cts . Token ) {
66+ Console . WriteLine ( "stopped" ) ;
67+ }
You can’t perform that action at this time.
0 commit comments