To my original question. When I write a file, is it possible to specify a timeout
I will have to defer to the C# experts to answer that one. It is documented here.
https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.writetimeout?view=netframework-4.8
But in my C# program it says that it is not supported when writing to a txt file. It might only apply to socket network streams. I don't know.
And to my original reply, if writing line by line over the network is problematic, write to the C drive to build the file and then do a file copy with retry and verification logic.
Do you know for a fact that file writes are taking minutes instead of milliseconds to finish? Do you have logging implemented to fully understand how long each I/O is taking? Does the I/O never complete? Do you get an error? You appear to be focused on this file write timeout, but at this point, I don't think that you know exactly what your problem is.
Have you done any analysis of activity on the target server? Are they doing a backup at the same time that your program is trying to write the file?
How can I test a network, good, bad, fast or slow.
Start with good old ping and monitor the time.
C:\>ping -t -l 2000 192.168.1.1
Pinging 192.168.1.1 with 2000 bytes of data:
Reply from 192.168.1.1: bytes=2000 time=5ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=3ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=5ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=144ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=149ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=153ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=32ms TTL=64
Reply from 192.168.1.1: bytes=2000 time=4ms TTL=64