编写windows 计划任务只需要在普通的类里面使用main方法就好了,因为任务计划在创建后走的是程序的主方法,代码如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace TestTask
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main(string[] args)
{
//其中args就是任务计划中的可添加参数,多个参数使用空格分开。
FileStream fs = new FileStream(@"d:\xx.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(, SeekOrigin.End);
foreach (var item in args)
{
sw.WriteLine("WindowsService(Thread): Write" + item + "\n");
}
sw.Flush();
sw.Close();
fs.Close(); Class1 c = new Class1();
//Thread thread = new Thread(c.OnStart);
//thread.Start();
c.OnStart();
c.OnStop();
} }
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace TestTask
{
public class Class1
{
public void OnStart()
{
//实现方法
FileStream fs = new FileStream(@"d:\xx.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(, SeekOrigin.End);
sw.WriteLine("WindowsService(Thread): Service Started" + DateTime.Now.ToString() + "\n"); sw.Flush();
sw.Close();
fs.Close();
} public void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
FileStream fs = new FileStream(@"d:\xx.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(, SeekOrigin.End);
sw.WriteLine("WindowsService(Thread): Service Stopped" + DateTime.Now.ToString() + "\n");
sw.Flush();
sw.Close();
fs.Close();
}
}
}

C# windows 计划任务 程序编写的更多相关文章

  1. Windows系统使用vbs脚本或bat脚本强制杀死指定所有进程 vbs实现循环持续写入内容到vbs打开开的记事本 使用vbs、bat添加windows计划任务 使用cmd schtasks命令添加windows计划任务

    以下脚本windows7下成功运行过,脚本也可以windows计划任务程序一起组合使用 新建一个记事本文档粘贴下面代码后将新建的记事本文档重命名下面对应的脚本名就能使用了: 添加windows计划任务 ...

  2. 如何在windows计划中调用备份sharepoint2010网站集的powershell脚本

    最近有个项目需要在在windows计划中使用powershell脚本备份sharepoint2010网站集,打开sharepoint的powershell执行命令管理界面的属性 查看: C:\Wind ...

  3. windows计划任务执行SQLserver脚本

    2016年3月1号,北京出差,documentbrowser系统改善上线. 其中有一个数据库表需要每天进行同步,原计划使用SQLServer的作业来执行又方便又快捷,但是客户的数据库是05的expre ...

  4. 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序

    原文 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 在 Visual Studio 2010 中开发和部署 Windows Azure 应用程序 Jim ...

  5. windows计划任务+批处理文件实现oracle数据库的定时备份与恢复

    1.  备份: PS:2014-1-15 如果导出的dmp数据文件不大的话,就直接每天导出好了,不要只保存七天的数据.然后顶起通过winrar对文件进行打包,我发现dmp文件的压缩包还是很高的. 那么 ...

  6. Windows计划任务执行时不显示窗口的问题

    最近开发了工具,带界面的,需要定时执行的,为了方便直接用Windows计划任务做定时了.跑了一段时间发现,进程中也有,就是看不到程序的界面,进程的执行貌似也阻塞了. 从网上查了下,发现时启动方式的问题 ...

  7. 基于DCMTK的DICOM相关程序编写攻略

    2008年09月10日 星期三 15:35 基于DCMTK的DICOM相关程序编写攻略 前言: 由于现在的医学影像设备的图像存储和传输正在逐渐向DICOM标准靠拢,在我们进行医学图像处理的过程中,经常 ...

  8. Fedora 11中用MinGW编译Windows的Qt4程序(在Linux系统下编译Windows的程序)

    Ubuntu下可以直接安装: sudo apt-get install mingw32 mingw32-binutils mingw32-runtime 安装后编译程序可以: i586-mingw32 ...

  9. 利用windows系统ftp命令编写的BAT文件上传[转]

    利用windows系统ftp命令编写的BAT文件上传[转] 利用windows系统ftp命令编写的BAT文件上传[转] 在开发中往往需要将本地的程序上传到服务器,而且用惯了linux命令的人来说.在w ...

随机推荐

  1. Nand Flash 基础

    1. 根据物理结构上的区别,Nand Flash主要分为: SLC(Single Level Cell): 单层式存储 MLC(Multi Level Cell): 多层式存储 TLC(Triple ...

  2. 通过.net core源码看下Dictionary的实现

    https://blog.csdn.net/narlon/article/details/80755386     .net core的代码位置 https://github.com/dotnet/c ...

  3. Window 远程连接 Ubuntu 系统

    安装XRDP 服务, 用windows远程连接ubuntu 1. Step 1 – Install xRDP sudo apt-get update sudo apt-get install xrdp ...

  4. 学习Laravel遇到的问题纪录

    1.更换git  remote $ git remote rm origin $ git remote add origin git@github.com:your_username/hello_la ...

  5. Linux文件操作常用选项

    常用选项 选项 功能 -a 查看隐藏文件 -l 列表方式查看 -h 人性化显示 * 通配符,忽略多个字符匹配 ? 通配符,忽略一个字符匹配 [Num1-Num2] 通配符,查看从Num1到Num2的匹 ...

  6. LeanTouch控制移动

    Lean_Touch控制移动 using UnityEngine; using System.Collections; using System.Collections.Generic; using ...

  7. [转]JavaScriptSerializer中日期序列化

    本文转自:http://www.cnblogs.com/songxingzhu/p/3816309.html 直接进入主题: class Student { public int age { get; ...

  8. db2 存储过程参数传递--字段类型转换产生的问题

    修改之前的脚本 select count(*) from dbdk.dtdkg010 A left join DBDK.DTDKG070 D ON D.PAY_NO = A.PAY_NO LEFT J ...

  9. (转)AIX 用户和组管理

    AIX 用户和组管理 原文:https://www.ibm.com/developerworks/cn/aix/library/au-aixuseradmin/ 管理 IBM AIX 中的用户和组是管 ...

  10. CRLF注入攻击

      原理:http数据包通过\r\n\r\n来分开http header何http body 实现:首先这种攻击发生在应用层,且发生在服务器返回给我们的http reponse没有经过敏感字符的过滤, ...