如何在C#中基于特定日期执行方法 [英] How to execute a method based on specific date in c#

查看:98
本文介绍了如何在C#中基于特定日期执行方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何在C#中基于特定日期执行方法?就像我有一个方法,我想在特定日期执行它.

谢谢.

Hello,

How to execute a method based on specific date in c#? like i have a method and i want to execute it on a particular date.

Thanks.

推荐答案

基本上,您需要有一些Windows服务,可以在特定条件下启动应用程序.

此类服务已经存在,旨在支持真正复杂的计划.它已经与Windows捆绑在一起并启用了;您可以在不同级别上使用它.它称为窗口任务计划程序",请参见 http://en.wikipedia.org/wiki/Windows_Task_Scheduler [ ^ ].

首先,您可以使用命令行实用程序AT.EXE或CSHTASKS.EXE(将替换AT.EXE)来安排事件,请参见:
http://en.wikipedia.org/wiki/At_%28Windows%29 [ ^ ],
http://en.wikipedia.org/wiki/Schtasks [ http://technet.microsoft.com/en-us/library/bb490866.aspx [ ^ ],
http://msdn.microsoft.com/zh-我们/library/windows/desktop/bb736357%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/aa383614%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/aa383608%28v=vs.85%29.aspx [ .NET的新任务计划程序类库 [ ^ ].



针对后续讨论:请参阅:
http://en.wikipedia.org/wiki/Push_technology [
Basically, you need to have some Windows Service which could start an application on certain conditions.

Such service already exists, It is designed to support really complex schedules. It is already bundled with Windows and enabled; you can use it on different levels. It is called Window Task Scheduler, see http://en.wikipedia.org/wiki/Windows_Task_Scheduler[^].

First, you can schedule events using command-line utilities AT.EXE or CSHTASKS.EXE (which is replacing AT.EXE), see:
http://en.wikipedia.org/wiki/At_%28Windows%29[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx[^].

And you also can use Window Task Scheduler API, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383614%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383608%28v=vs.85%29.aspx[^].

To see how can you use it with .NET, see this CodeProject article: A New Task Scheduler Class Library for .NET[^].



In response to follow-up discussion: please see:
http://en.wikipedia.org/wiki/Push_technology[^].

—SA


看看这个,您肯定会得到答复的:
http://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c [> http://stackoverflow.com/questions/1681465/c-sharp-execute- function-at-specific-time [ ^ ]
Have a look on this,you will surely get answered:
http://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c[^]
http://stackoverflow.com/questions/1681465/c-sharp-execute-function-at-specific-time[^]


如已经建议的那样,您可以在此处使用Windows服务在所需的时间执行任务.

您的评论说此事件处理程序/方法位于ASP.Net应用程序中.现在,如果ASP.Net应用程序中没有真正触发它的东西,则不需要其中的方法.您可以创建一个在服务器上运行的新Windows服务,并在需要时进行处理.
As already suggested you can make use of Windows service here to perform the task on the desired time.

Your comment stated this event handler/method resides in the ASP.Net application. Now, if there nothing really in the ASP.Net application that triggers it you do not need to have the method in it. You can create a new Windows service that runs on the server and do processing as and when needed.


这篇关于如何在C#中基于特定日期执行方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆