USe the Stopwatch Class (System.Diagnostics) | Microsoft Docs
] - it works in ticks, which is teh finest resolution the system can provide, and runs up to 290 years.
Start it when you connect, stop it when you disconnect. At any point in between you can use teh Stopwatch.ElapsedTicks Property (System.Diagnostics) | Microsoft Docs
] to tell you how long it's been connected.