×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Switzerland
    Posts
    476

    Weird "Battery Discharge Time"

    Hello

    In order to get the time since the last device reboot, I'm using the following code snippet:

    Code:
    this.Items_HAL.Add(new ItemViewModel() { LineOne = "Time since last reboot", LineTwo = string.Format("{0} d {1} h {2} min", (System.Environment.TickCount / 1000 / 60 / 60 / 24).ToString(), ((System.Environment.TickCount / 1000 / 60 / 60) % 24).ToString(), ((System.Environment.TickCount / 1000 / 60) % 60).ToString()) });
    As you can see, I'm calculating this information by using the system's TickCount. According to the documentation, this is a 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.

    Anyway, running the aforementioned code on a Windows Phone 8, I get something weird like this:
    10675199 d 2 h 48 min --> the number of days is much too high

    Can someone help me to figure out the problem?

    Thanks,
    Patrick
    Last edited by patrickfrei; 2013-11-16 at 22:29.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,697

    Re: Weird "Time Since Last Device Reboot"

    That number does not seem like something what you can get via dividing a 32-bit integer with 1000*60*60*24.
    e.g. 10675199 is a 24-bit number, and if you multiply it back, the result is 922337193600000, an 50-bit number.

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    511

    Re: Weird "Time Since Last Device Reboot"

    Interesting - what device are you seeing the issue on? I ran your code inside a MessageBox and it worked on both my 1020 (GDR3) and inside the Emulator (GDR2).

    Can you give us the raw value System.Environment.TickCount gives on your device?

  4. #4
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Switzerland
    Posts
    476

    Re: Weird "Battery Discharge Time"

    I'm really sorry, but I've just seen that I've provided the wrong code...

    Here's the correct one:
    Code:
    this.Items_General.Add(new ItemViewModel() { LineOne = "Battery Discharge Time", LineTwo = string.Format("{0} d {1} h {2} min", Battery.GetDefault().RemainingDischargeTime.Days, Battery.GetDefault().RemainingDischargeTime.Hours, Battery.GetDefault().RemainingDischargeTime.Minutes) });
    It's the battery remaining discharge time that's so high. I've seen that the retrieved value is only so extremly high, when the phone is connected to a charger. Anyway, this behaviour is really strange...
    Last edited by patrickfrei; 2013-11-16 at 22:28.

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    511

    Re: Weird "Battery Discharge Time"

    Well, it should basically be Infinity, given that the phone won't discharge at all when it's connected to the charger. I would suggest to simply set the value to a fixed symbol when you detect the phone being connected to the charger.

  6. #6
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Switzerland
    Posts
    476

    Re: Weird "Battery Discharge Time"

    Yes, that's a good idea. Will do this. Thank you for your help.

Similar Threads

  1. Replies: 10
    Last Post: 2011-05-17, 18:00
  2. Weird "Network communication failure." on express signing
    By ralle@envicon.de in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 1
    Last Post: 2009-01-29, 11:06
  3. Replies: 1
    Last Post: 2008-08-26, 10:56
  4. Replies: 2
    Last Post: 2008-08-21, 12:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×