c#,windows service,system.threading.timer
2008-07-17 17:43 Virus-BeautyCode 阅读(1639) 评论(0) 编辑 收藏 举报using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;
using System.Threading;
namespace WinSer
{
public partial class Service1 : ServiceBase
{
System.Threading.Timer timer1=null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
timer1 = new System.Threading.Timer(new TimerCallback(timer1_Tick), null, 0, 60000);
}
void timer1_Tick(object obj)
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "Client")
{
p.Kill();
return;
}
}
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;
using System.Threading;
namespace WinSer
{
public partial class Service1 : ServiceBase
{
System.Threading.Timer timer1=null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
timer1 = new System.Threading.Timer(new TimerCallback(timer1_Tick), null, 0, 60000);
}
void timer1_Tick(object obj)
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "Client")
{
p.Kill();
return;
}
}
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
}