0

I want to built a WPF application that records the battery level of the user every minute. I want my app to have user interface of course. Is it ok to develop a console application that runs in the background and saves the current battery level in a text file? Later when the user wants to see the data and opens the WPF application it can read it from that text file. Is it a good practice or there is a better way to do it?

snaksa
  • 448
  • 1
  • 5
  • 15
  • There is a *much* better way to do it using .NET task async pattern, though it's quite a steep learning curve for beginners. You can start here: https://msdn.microsoft.com/en-us/library/hh873177%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 – rory.ap Feb 27 '15 at 15:10
  • Why do you even need an app? Perfmon will do exactly this for you http://www.maketecheasier.com/windows-8-performance-monitor-to-analyse-system/ – Paolo Feb 27 '15 at 15:17
  • @Paolo, I want to do it for practise. – snaksa Feb 27 '15 at 15:30
  • Use a DispatcherTimer. – patrick Feb 27 '15 at 17:29

1 Answers1

0

Do you really need to get the battery level "in the background"? Typically, you only need to do background operations when you have a long-running task that will affect the user experience by causing the UI to "hang".

There is a much better way to do it using .NET task async pattern, though it's quite a steep learning curve for beginners. You can start here: https://msdn.microsoft.com/en-us/library/hh873177%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1. Basically, you would offload any long-running operations to an awaitable task so your UI remains responsive throughout the operation.

I still feel like getting the battery level wouldn't be a lengthy operation that would affect the UI. In that case, you could accomplish what you want via a timer that runs every minute.

Community
  • 1
  • 1
rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • Thank you! Looks like the timer will be the best choice. And when the user minimizes the window it will go to the notification area box and still do the operation every minute. – snaksa Feb 27 '15 at 15:26