一个简单的Windows服务应用程序范例
来源:互联网 发布:计算机编程中常见的 编辑:程序博客网 时间:2024/05/08 02:35
1:创建一个Windows服务应用程序
2:我写了一下代码
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Linq;using System.ServiceProcess;using System.Text;using System.Timers;using System.Data;using System.Data.SqlClient;using System.Configuration;namespace WindowsServiceDemo{ public partial class Service1 : ServiceBase { Timer EventTimer;//事件计时器 int Times = 0; public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { EventTimer = new System.Timers.Timer(); EventTimer.Interval = 1000; EventTimer.Elapsed+=new System.Timers.ElapsedEventHandler(Timer_Event); EventTimer.Enabled = true; } private void Timer_Event(object sender,ElapsedEventArgs e) {
//自定义需求代码 Times++; //连接数据库 string ConnectionString = ConfigurationManager.ConnectionStrings["WindowsServiceDemoConnectionStrings"].ConnectionString.ToString(); SqlConnection conn = new SqlConnection(ConnectionString); conn.Open(); //数据库操作 string sql_Insert = "INSERT INTO VIP VALUES('"+Times+"程咬金','"+Times+"8661269572')"; SqlCommand cmd_Insert = new SqlCommand(sql_Insert,conn); cmd_Insert.ExecuteNonQuery(); conn.Close(); } protected override void OnStop() { this.EventTimer.Enabled = false; } }}
0 0
- 一个简单的Windows服务应用程序范例
- 一个简单的区分服务范例
- 一个简单的Windows服务
- NET编写简单的Windows 服务应用程序
- -一个简单的windows GUI应用程序
- 一个最简单的Windows应用程序
- 一个简单的 fwrite 范例
- 一个简单的Java范例
- Jackson的一个简单范例
- 一个简单的C# WINDOWS服务程序
- C#一个简单windows服务的例子
- 编写一个简单的windows服务
- 【C#】一个简单的windows服务程序
- C# 写一个简单的Windows服务
- JBPM建一个简单的范例
- 一个剖析AJAX原理的简单范例
- 如何利用CEF3创建一个简单的应用程序 (Windows Platform)
- 如何创建一个最简单的Windows桌面应用程序 (C++)
- 数据挖掘算法概念与经典算法简介
- java 观察者模式
- hpuoj1691 CZY追女孩
- Timus Online Judge 2055 Urban Geography 动态树维护mst(第44case超时了)---留着以后做吧
- UML简介
- 一个简单的Windows服务应用程序范例
- JList的使用实例
- Microsoft SQL Server基础知识复习
- 再续tableView
- UVA 10635 - Prince and Princess ( LCS 转换为LIS )
- Objective—C中声明实例变量的两种方式
- C 语言学习 3
- Hadoop添加和撤销节点
- NetBeans IDE中文界面修改成英文界面