c# window服务-初学习
window服务-初学习
一、工具:
VS2015+NET Framework4.5。
二、操作:
1、新建windows服务的项目:
2、修改windows服务相关内容:
3、预览windows服务代码结构:
4、windows服务生成与发布:
三、代码:
1、测试代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
using ClassLibrary1; 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.Threading; using System.Threading.Tasks; namespace WindowsServiceTest { public partial class Service1 : ServiceBase { public Service1() { InitializeComponent(); } protected override void OnStart( string [] args) { Thread thread = new Thread( delegate () { try { for ( int i = 0; i < 1000; i++) { LogHelp.WriteLog( "服务启动" + i); } } catch (Exception ex) { LogHelp.WriteLog( "服务启动失败" + ex); ; } } ); thread.Name = "线程测试1" ; thread.IsBackground = true ; thread.Start(); } protected override void OnStop() { } } } |
2、bat文件代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
安装服务代码: sc delete WindowsServiceTest sc create WindowsServiceTest start= auto binPath= D:\www\Debug\WindowsServiceTest.exe sc description WindowsServiceTest "BY Eadily" pause 卸载服务代码: net stop WindowsServiceTest sc delete WindowsServiceTest |
四、总结:
记录每一天的点滴,码好每一行的代码
c# window服务-初学习的更多相关文章
- clisp, scheme 和 clojure 初学习
clisp, scheme和clojure 初学习 1 clojure "clojure绝对会成为你的编程工具箱里的终极武器" "其他语言可能只是工具,但 Clojure ...
- .NET Window服务启动又马上停止,报错IO.FileNotFoundException
最近公司需要开发一个Window服务推送系统,读取MongoDB写入消息队列,推送到各终端平台 但是在开发完成,最后的部署阶段,选中服务右击启动 看似正常,服务显示已启动(但实质已经被终止,因为Win ...
- C#编写window服务,一步一步(1)
Window服务是啥,这里就不废话了,如何用在哪里用也不废话了,这里我这篇文章只是详述了我在vs2012中创建window服务的经过,希望对你有所帮助. 另外:我在编写服务过程中参考了 Profess ...
- WPF Window 服务安装
一.安装服务 1.已管理员的身份启动CMD 2.输入 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 回车 3.输入 InstallUtil.exe ...
- Window服务初级教程以及log4net配置文件初始化
Window服务初级教程:http://www.jb51.net/article/48987.htm 另外,配置log4net这个日志功能的时候需要初始化,不然会报没有初始化的错误,而且初始化的节点应 ...
- C# 编写Window服务基础(一)
一.Windows服务介绍: Windows服务以前被称作NT服务,是一些运行在Windows NT.Windows 2000和Windows XP等操作系统下用户环境以外的程序.在以前,编写Wind ...
- C# 编写短信发送Window服务
我们做项目过程中,一般都会有发送短信的需求.最常见的就是户注册或者登录时发送短信验证码.不同类型的短信发送,我们都可以放到到一张短信表中,然后通过一个定时的作业去执行短信发送.而定时作业的执行,我们就 ...
- 自定义Window 服务
自定义window 服务 开发到使用的流程: 1.完成对应的代码之后(代码在底下),右键MyService.cs 添加安装程序 2.添加window服务安装程序打开Service1.cs[设计]页面, ...
- window服务创建
第一步:创建服务 第二步:在Service1.cs视图中 右键 选择”添加安装程序” 这里要注意几个细节 设置上面的属性 这两个分别有属性,具体网上查使用方式 3 实例代码编写 主要下面几个方法 pr ...
随机推荐
- LA 6437 Power Plant (prim最小生成树)
还是裸的最小生成树 #include<bits/stdc++.h> using namespace std; int T,N,M,P,K,a,b,c; int dist[1020],m[1 ...
- oracle实现自增id
--oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...
- nodejs中require的路径是一个文件夹时发生了什么
node中使用require的时候如果路径是一个文件夹时,或者特殊的情况require('..');require('.'); 这是node实战这本书里说的情况,但是我在node6.9版本中发现不完全 ...
- NOIP2017提高组模拟赛 7(总结)
NOIP2017提高组模拟赛 7(总结) 第一题 斯诺克 考虑这样一个斯诺克球台,它只有四个袋口,分别在四个角上(如下图所示).我们把所有桌子边界上的整数点作为击球点(除了4个袋口),在每个击球点我们 ...
- bzoj1570: [JSOI2008]Blue Mary的旅行(二分+网络流)
1570: [JSOI2008]Blue Mary的旅行 题目:传送门 题解: get到拆点新姿势,还是做题太少了...ORZ 因为每天就只能有一个航班,那就不能直接连了,所以要拆点(然后就被卡住了) ...
- bzoj4568: [Scoi2016]幸运数字(LCA+线性基)
4568: [Scoi2016]幸运数字 题目:传送门 题解: 好题!!! 之前就看过,当时说是要用线性基...就没学 填坑填坑: %%%线性基 && 神犇 主要还是对于线性基的运用和 ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- 14.MongoDBUtils工具类
1. public class DbUtils { public static MongoCollection<Document> getMongoCollection(String lo ...
- Ubuntu16.04+OpenCV3.2.0+Opencv_Contrib3.2.0安装
为了学习slam,在ubuntu16.04系统上安装opencv3.2.0以及对应的opencv_contrib3.2.0 安装过程 下载 Github上下载有的时候比较慢,我这里分享了OpenCV3 ...
- Windows下本机简易监控系统搭建(Telegraf+Influxdb+Grafana)--转
原文地址:http://www.cnblogs.com/liugh/p/6683488.html 一.文件准备 1.1 文件名称 telegraf-1.2.1_windows_amd64.zip in ...