How to track time between two button clicks in C# in a Windows form application?

前端 未结 3 1374
青春惊慌失措
青春惊慌失措 2021-01-29 00:06

I have created a windows form application in c# in which input from user is taken .I want to calculate time spent by user in between two submissions.How can I do that?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 00:44

    Using System.Threading you can use the stopwatch function. Just start the function on the first click and stop it on the second.

    Using System.Threading
    
    //main etc ignored
    
    //declare
    
    Stopwatch s = new Stopwatch();
    
    //start
    s.start();
    //stop
    s.stop()
    //get the time
    s.Elapsed;
    

提交回复
热议问题