示例#1
0
        // 提示音提醒 方法
        private void Ring()
        {
            Stream stream = TitleContainer.OpenStream(SoundModel.GetSoundUriByID(soundId));

            effectInstance = SoundEffect.FromStream(stream).CreateInstance();
            FrameworkDispatcher.Update();
            int times = 20;

            new Thread(new ParameterizedThreadStart(param =>
            {
                do
                {
                    if (effectInstance.State.Equals(SoundState.Stopped))
                    {
                        effectInstance.Play();

                        times--;
                    }
                    Thread.Sleep(2000);

                    if (times == 0)
                    {
                        break;
                    }

                    if (loopPlay == false)
                    {
                        break;
                    }
                } while (true);
            })).Start();
        }
示例#2
0
        private void phoneApplicationService_Deactivated(object sender, DeactivatedEventArgs e)
        {
            // 重复模式下,不添加到系统提示。
            if (timingViewModel.IsRepeat)
            {
                return;
            }
            Alarm alarm    = new Alarm("alarm");
            var   soundUri = SoundModel.GetSoundUriByID(soundId);

            if (string.IsNullOrEmpty(soundUri))
            {
                // alarm.sound 空白或滴
                alarm.Sound = new Uri("Sounds/BeepNone.wav", UriKind.Relative);
            }
            else
            {
                alarm.Sound = new Uri(soundUri, UriKind.Relative);
            }
            DateTime now      = DateTime.Now;
            DateTime showTime = DateTime.Parse(timingViewModel.ShowTime);

            now                  = now.AddHours(showTime.Hour);
            now                  = now.AddMinutes(showTime.Minute);
            now                  = now.AddSeconds(showTime.Second);
            alarm.BeginTime      = now;
            alarm.ExpirationTime = now.AddMinutes(5);

            alarm.Content = timingViewModel.InputCountdownTime.ToString("HH:mm:ss") + "\r\n" + timingViewModel.Name;
            try
            {
                if (alarm.BeginTime.Second <= 30 && alarm.BeginTime.Hour == DateTime.Now.Hour && alarm.BeginTime.Minute == DateTime.Now.Minute)
                {
                    alarm.BeginTime = alarm.BeginTime.AddMinutes(1);
                }

                if (ScheduledActionService.Find(alarm.Name) != null)
                {
                    ScheduledActionService.Remove(alarm.Name);
                    Logger.Log("ScheduledActionService.Replace(alarm);");
                }
                ScheduledActionService.Add(alarm);
                Logger.Log(" ScheduledActionService.Add(alarm);");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }