I have a windows form application that connects to a USB port.
In the method, there would be a while(!connected) to attempt to connect to the port endlessly.
How do I create a TimeSpan(?) variable to limit the connection to around maybe 10 seconds before it stops trying to connect and display a messagebox saying
“Connection failed. Please try again.”
Thanks!
Why not just record the start time as a DateTime?
You can then periodically check the connection duration:
You can then simply test the following