I have a requirement in my application where I need to create the file in a network drive, but when file creation in progess if network disconnected application hangs for a while and throws an exception.
Is there any way we can set time-out for File.Create
?
Something like that can be used to implement time-out manually:
var fileCreatingThread = new Thread(...);
fileCreatingThread.Start();
if (fileCreatingThread.Join(TimeSpan.FromSeconds(5)) { /* Worked correctly */}
else
{
// time-out
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With