DEAR ALL:
怎样一个服务内按一定的频率(每月或每天)执行某一作业
感谢100分!
怎样一个服务内按一定的频率(每月或每天)执行某一作业
感谢100分!
解决方案 »
- c#中double类型如何保留小数点后2位。
- GZipStream 压缩
- [winforms]: 字符屏幕显示
- Access 创建存储过程的问题?
- 怎样获得系统安装的某个特定打印机的打印环境(PrinterSettings),致谢!
- showdialog()关闭后刷新父窗体
- 我已经用工具添加数据把C#和SQL连接好了,怎么调用数据库里的数据呢?
- 请问datagrid控件的表头可以两项合并成一项吗?
- dropdownlist为什么不能触发事件?
- 如何实现像windows应用程序一样在我的web页面上弹出messagebox
- 怎么关闭窗体
- byte[] bb 有10000个字节.怎么把它分包分成2个包?每个包各有5000个字节.
可以使一个服务内按一定的频率(每月或每天)执行某一作业具体看Sql帮助,SQl Server提供了设置界面,不用手写代码.
http://community.csdn.net/Expert/topic/4211/4211229.xml?temp=.3633081可以把里面那些代码提出来写到一个webservices里面,设定好时间,然后时间一到就执行你的作业
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.ServiceProcess;namespace MyNameSpace
{
public class MyClass : System.ServiceProcess.ServiceBase
{
private System.ComponentModel.Container components = null; //自定义成员声明
private System.Timers.Timer objTimer=new System.Timers.Timer();
public MyClass()
{
// 该调用是 Windows.Forms 组件设计器所必需的。
InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化
} // 进程的主入口点
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 同一进程中可以运行多个用户服务。若要将
// 另一个服务添加到此进程,请更改下一行
// 以创建另一个服务对象。例如,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyClass() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun);
} /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ServiceName = "MyWindowsService"; } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} /// <summary>
/// 设置具体的操作,以便服务可以执行它的工作。
/// </summary>
protected override void OnStart(string[] args)
{
MyTimer();
}
/// <summary>
/// 停止此服务。
/// </summary>
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
objTimer.Enabled = false;
objTimer.Elapsed -= new System.Timers.ElapsedEventHandler(MTimedEvent);
}
//--以下是自定义函数
private void MyTimer()
{
System.Timers.Timer MT = new System.Timers.Timer (new TimeSpan(1,0,0,0,0)); //一天一次
MT.Elapsed += new System.Timers.ElapsedEventHandler(MTimedEvent);
//MT.AutoReset =false;
//MT.Start();
MT.Enabled = true; }
//构造System.Timers.Timer实例 间隔时间事件
private static void MTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
MyJob();
} private static void MyJob()
{
.
.
.
.
.
.
}
}
}