Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In TCP/IP C# programming i want to know for how much time the socket was connected ?(THE EXACT TIME from the day it was connected until now)


What I have tried:

looking for code................................................................
Posted
Updated 17-Aug-18 20:00pm

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900