-3

I was wondering if i could get a little help. I am working on a WPF application and i have to keep track how long it takes a user to make a report(make a report is one of the buttons), want the amount of time elapsed between when the XAML view is first shown (loaded) to the user and when the user clicks the 'Submit' button

LuDevGon
  • 113
  • 1
  • 9

1 Answers1

1

This is how I would approach it. Define 2 private member variable of type Datetime. Let's name those variables startTime and endTime. Wire-up the XAML Window's Loaded event. In the Loaded event set the startTime = DateTime.Now. In the event handler for the 'Submit' button set endTime = DateTime.Now. To get the total elapsed time simply subtract the startTime from the endTime (var elapsedTime = endTime - startTime). The process should be able to be repeated unless this is the main control of your application and is always in scope. So, if this is your main Window that stays open you'll need a way to set the startTime for each subsequent operation. Maybe re-set the startTime right after you retrieve the elapsed time. Hope this helps!

Mark Harrington
  • 308
  • 4
  • 10