【发布时间】:2014-08-23 05:55:19
【问题描述】:
我正在尝试创建一个 WPF 媒体应用程序以使用 Media Element 运行音频文件。 我成功了。但我想安排重复播放我在某个时间间隔内选择的歌曲。在每天或每小时等中说 10 点。
最好的方法是什么?
最初我考虑使用计时器来做这件事。但这使我的代码变得复杂,因为我必须以用户设置的不同间隔播放多首歌曲。
最近我去了解Task Scheduler,我运行了他们的示例代码[打开记事本],它运行良好。
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
// Remove the task we just created
ts.RootFolder.DeleteTask("Test");
}
如何定义在此上下文中播放歌曲的动作?目前他们提供 ExecAction、SendEmail、ShowMessage 和 ComHandlerAction see this link
或者我们可以通过这个任务计划程序调用我的应用程序的播放方法吗?请提供任何想法帮助我。
谢谢
【问题讨论】:
标签: c# wpf winforms silverlight scheduled-tasks