Example #1
0
        internal static async Task PreLaunchAsync(LaunchActivatedEventArgs e)
        {
            // Start tracking app usage (launch count, uptime, ...)
            try
            {
                // Make the AppUptime cumulative over sessions.

                // v1.0
                // Does not work because AppUptime returns TimeSpan.MinValue too often.
                // var uptimeSoFar = SystemInformation.AppUptime;
                // if (uptimeSoFar == TimeSpan.MinValue)
                // {
                //     uptimeSoFar = TimeSpan.FromSeconds(0);
                // }

                // v2.0
                var uptimeSoFar = TimeSpan.FromTicks(new LocalObjectStorageHelper().Read <long>("AppUptime", 0));

                SystemInformation.TrackAppUse(e); // Resets AppUptime to 0.
                SystemInformation.AddToAppUptime(uptimeSoFar);
            }
            catch (Exception)
            {
                SystemInformation.TrackAppUse(e);
            }

            await Task.CompletedTask;
        }