Cant Get PC Idle Time - c#

I found a Tutorial on how to get the idle time of PC. how ever when i run the sample the idle time is always 0 no matter how idle i leave my pc!
the system Up-time is working good but the Idle Time is always 0! any idea why this is happening ?
Windows 7 64bit

I'm in danger of telling you what you probably already know, but that code is for user idle time rather than system idle time.
Using Environment.TickCount is a questionable practice as the value starts at 0, goes up to X (after about 25 days) and then wraps round to -X. So you can't always use straight subtraction as the code suggests.
http://msdn.microsoft.com/en-us/library/system.environment.tickcount(v=vs.80).aspx
Given that you're on running it on a PC though, this should be fine (assuming you reboot fairly regularly).
Depending on how you're running it, you may also want to have a look at this:
GetLastInputInfo API doesn't work if windows is set to "Automatic Login"

Related

How to know last boot up time for fast boot settings

I was using WMI to get the last boot date/time. But with fast boot enabled, boot up time is not reset and thus I am not getting what I expected. How can I know if it got booted(may not be cold shutdown) in C#? I have seen powershell command that lists boot up time and type(it didn't work when i tried in powershell). I don't know how to do it in C# or some other way is there to know it.

Application Halt for few second on some client's systems

i have a chat application which is perfectly working on debug mode and also running smoothly on client's machines but from last 2 days it's UI get stuck/halt for 10-30 seconds after that it start running again, this process of halt and running happen continuously. its happening only on few machines. i don't know where to start. All users are sitting on same floor so that's not an internet issue neither a system memory issue. If you guys think its a memory issue let me know what to check then?
it was due to internet, The machines where software was halting are on different internet which is little slow so that's is why this issue is occurring.

Windows 8 Phone periodic task not running

I went through the following documentation to create a background periodic task:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202941(v=vs.105).aspx
For some reason, I never see it running. (In the sense, the OnInvoke() method in the class SchedulerTaskAgent.cs never got invoked)
With debugger on, I was able to invoke the method using:
if(DEBUG_AGENT)
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
It ran fine every 60 seconds. I saw the debug statements I added to OnInvoke() getting printed every minute (60 seconds).
Then I commented out the above lines to test to see if OnInvoke() gets called by the OS at times (say like every 30 minutes or so).
It was never called. I connected the phone to my Windows computer and the phone was fully charged, but was not connected to Wifi, but to the cellular network.
I am not sure as to understand why it was not triggered. I attempted the whole day yesterday (at least 6 to 8 times waiting between 30 minutes and an hour).
How do I test periodic task in the real world scenario where I can't use: ScheduledActionService.LaunchForTest(...)
My phone was simply idling and the phone I use is exclusive for testing (I don't have any apps running in the background,the cellular network signal was really good, with battery up to 100%).
Also the periodic task is just going to print some messages and not going to do any network or resource-intense activity.
Thanks for your time.
Try adding a pound sign in front of the if.
eg.
#if(DEBUG_AGENT)
ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif

WinRT timeout during a webrequest to detect slow internet connections

Is there a sample code available online to get WinRT to determine if its a slow internet connection within the first second of a web-request call so that I can cancel the request and switch to a local file at the start of the program. Metro requirements expect the app to boot up under 5 seconds and I need my web-request (of 300kb) to return well before that. its usually fast on WiFi but 3G speed may vary.
You can see if you are running on a 3G or WiFi connection by using the connectioncost api.
When you are on 3G you could consider using the local file anyway and then attempt to update it on the background. Additionally you might increase your logic further by checking if the user is currently roaming or even if he or she is approaching his or her datalimit, all which might influence your decision on where to load from. All this can be done through the same API.
You are also mixing up things a little as far as the 5 seconds for your app to start go. Your app can actually take 15 seconds give or take to provide something and only 5 seconds to suspend before you are forcibly cut off. If the 15 seconds isn't enough to start with you can also replace the default splash screen .. with your own splash screen and continue loading as long as you like. Keep in mind your user might not like it.
Why not load the local file and then try to update it on the background? I am not sure about your use case.

Possible to accurately calculate difference two DateTimes on Windows Phone 7 even if the user changes phone clock?

I am currently making a small timer application for Windows Phone 7 with data logging capabilities so people can see how long they spent performing a task in a given day.
They need be able to close the application, answer phone calls, etc. and the application will appear to continue counting (since there's no multitasking in WP7 for 3rd party). I am currently doing this by storing the time the timer was last updated and calculating the difference between the time now.
Right now I have the following code which is executed when the timer updates (every second / on Application Activation):
TimeSpan tempNowLastDiff = DateTime.Now - LastUpdateTime;
CumulativeTime += tempNowStartDiff;
LastUpdateTime = DateTime.Now;
The problem is if the person exits the application and changes the clock, when the application starts again the the CumulativeTime is no longer accurate. If I change the clock back, it can result in a negative TimeSpan, if I change the clock forward it can result in an overly positive TimeSpan.
The only solution I can think of is to 0 the difference if tempNowStartDiff is negative and to just assume the task was for 24 hours every day if positive (which is possible if, say, they go on a road trip).
Is there any way to get an absolute time which will not be affected by phone time changes?
If not, is there a way to check if the time was changed and by how much?
Edit: I've uploaded a copy of the Timer code here with instructions on how to replicate issue.
I would use DateTime.UtcNow to have a absolute value because DateTime.Now is relative to the current timezone and so the phone can change the time automatically if they change of timezome (from the GSM network).
In that case the only solution i can think of is to get the time from somewhere outside like from timeanddate.com

Categories

Resources