I have a question about a scenario I need to code. I have a process that will send a request file via SFTP and then I will need to wait for a response file to be created on the ftp server before I download and continue my processing. The response file could take anywhere between 1min to 60mins to appear. If I await this process, is there a way that I can say, give up after 60 mins? C#
Asked
Active
Viewed 128 times
1
-
2You could add an CancelationToken with a duration of 60Minutes – TheTanic Mar 16 '22 at 09:50
-
How are you sending the request file via SFTP? Is the send operation cancellable? – Theodor Zoulias Mar 16 '22 at 10:00
-
2^^ Also, it would be interesting how you track and wait for the "response file" to appear. Best would be to post the relevant code. – Fildor Mar 16 '22 at 10:03
1 Answers
1
Use a CancellationTokenSource
private CancellationTokenSource _cancellationTokenSource =
new CancellationTokenSource(TimeSpan.FromMinutes(60));
Wrap the code in a try/catch and watch for TaskCanceledException
Also, check out Asynchronously wait for Task to complete with timeout

Karen Payne
- 4,341
- 2
- 14
- 31