| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:[求助]谁有windows服务的项目代码?
只看楼主 加入收藏
白菜粉条
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-5-25
收藏
 问题点数:0 回复次数:1 
[求助]谁有windows服务的项目代码?

我不知道如何下手,想参考下!谢谢!

搜索更多相关主题的帖子: windows 项目 代码 服务 
2007-07-24 09:40
guoxhvip
Rank: 8Rank: 8
来 自:聖西羅南看臺
等 级:贵宾
威 望:44
帖 子:4052
专家分:135
注 册:2006-10-8
收藏
得分:0 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;

namespace WindowsService
{
public class Service1 : System.ServiceProcess.ServiceBase
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Service1()
{
// 该调用是 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 Service1() };

System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
}

/// <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)
{
StreamWriter sw = new StreamWriter("D:/Log.txt",true);
string time = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":"
+ DateTime.Now.Second.ToString();
string time1 = "00:00:00";
string time2 = "12:00:00";
string time3 = "18:00:00";
if(time.CompareTo(time1) >= 0 && time.CompareTo(time2) < 0)
sw.WriteLine("早上好");
else if(time.CompareTo(time2) >= 0 && time.CompareTo(time3) < 0)
sw.WriteLine("下午好");
else
sw.WriteLine("晚上好");
sw.Flush();
sw.Close();
}

/// <summary>
/// 停止此服务。
/// </summary>
protected override void OnStop()
{

}
}
}


愛生活 && 愛編程
2007-07-24 17:11
快速回复:[求助]谁有windows服务的项目代码?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017117 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved