C#Windows服务程序的快速开发向你介绍了在很多应用中需要做windows服务来操作数据库等操作,希望对你了解C#Windows服务程序的开发有所帮助。
C#Windows服务程序的快速开发:在很多应用中需要做windows服务来操作数据库等操作,比如
(1)一些非常慢的数据库操作,不想一次性去做,想慢慢的通过服务定时去做,比如定时为数据库备份等
(2)在.net Remoting中利用windows服务来做Host
利用vs.net我们可以在几分钟之内建立其windows服务,非常简单
下面说一下C#Windows服务程序的快速开发的步骤
C#Windows服务程序的快速开发1. 新建一个项目
C#Windows服务程序的快速开发2. 从一个可用的项目模板列表当中选择Windows服务
C#Windows服务程序的快速开发3. 设计器会以设计模式打开
C#Windows服务程序的快速开发4. 从工具箱的组件表当中拖动一个Timer对象到这个设计表面上 (注意: 要确保是从组件列表而不是从Windows窗体列表当中使用Timer)
C#Windows服务程序的快速开发5. 设置Timer属性,Interval属性200毫秒(1秒进行5次数据库操作)
C#Windows服务程序的快速开发6. 然后为这个服务填加功能
C#Windows服务程序的快速开发7.双击这个Timer,然后在里面写一些数据库操作 ......
我们做了程序,不免会有版本升级,这就需要程序有自动版本升级的功能。
那么看看我是如何实现程序自动更新的。
直接上代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using System.Net;
using System.Xml;
namespace Update
{
/// <summary>
/// 更新完成触发的事件
/// </summary>
public delegate void UpdateState();
/// <summary>
/// 程序更新
/// </summary>
public class SoftUpdate
{
private string download;
private const string updateUrl = "http://www.csdn.net/update.xml";//升级配置的XML文件地址
#region 构造函数
public SoftUpdate() { }
/// <summary>
/// 程序更新
/// </summary>
/// <param name="file">要更新的文件</param>
public SoftUpdate(string file,string softName) {
this.LoadFile = file;
this.SoftName = softName;
}
#endregion
#region 属性
private string loadFile;
private str ......
继承是派生类(子类)去实现(重写<override>、重构<new>)基类(父类)的方法或属性。从而获取在派生类中要实现的功能。
子类调用父类构造方法,在父类中有个实现姓名和年龄的构造方法但是中子类也要实现这样的功能这时子类不用再次去写这个功能只要去调用父类的功能即可。
public class Person
{
private string _name = null;
private int _age = 0;
public Person(string name, int age)//父类的构造方法
{
this._name = name;//获得参数的值
this._age = age;
Console.WriteLine("您的姓名是{0},您的年龄是{1}.",
&n ......
public struct RECT
{
public int left;
public int Top;
public int Right;
public int Bottom;
}
public static bool CenterMouseOn(int hwnd)
{
int x=0;
int y=0;
int maxX=0;
int maxY=0;
RECT crect=new RECT();
int gFound=0;
GetDisplayResolution(ref maxX,ref maxY);
gFound=GetWindowRect(hwnd,ref crect);
&nbs ......
public struct POINTAPI
{
public int x;
public int y;
}
public static void GetWindowfromPoint(ref int hwnd,ref StringBuilder winText,ref StringBuilder clsName,ref StringBuilder pText)
{
int parentHandle=0;
int maxLen=128;
POINTAPI pnt = new POINTAPI();
parentHandle=GetCursorPos(ref pnt);
hwnd=WindowfromPoint(pnt.x,pnt.y);
winText =new StringBuilder(maxLen);
parentHandle=GetWindowText(hwnd,winText,maxLen);
clsName=new StringBuilder(maxLen);
parentHandle=GetClassName(hwnd,clsName,maxLen);
pText=new StringBuilder(maxLen);
parentHandle=GetParent(hwnd);
parentHandle=GetWindowText(parentHandle,pText,maxLen);
} ......
无意中看到ref关键字,只记得一开始学习C#的时候,有很多东西都跳过去了。 今天刚看见这个关键字的时候,还真不知道它有什么特别的地方。google了一下,找到一篇解释的比较 好的文章。如下: C# 中的变量 C# 中的数据有两种类型:引用类型(reference types)和值类型(value types)。 简单类型(包括int, long, double等)和结构(structs)都是值类型,而其他的类都是引用类型。 简单类型在传值的时候会做复制操作,而引用类型只是传递引用,就像 C++ 中的指针一样。注意 structs 在 C# 和 C++ 中的区别。在 C++ 中, structs 和类基本相同(except that the default inheritance and default access are public rather than private)。 而在 C# 中,structs 和类有很大的区别。其中最大的区别(我个人觉得,同时也是容易忽略的一个地方)可能就是它是值类型,而不是引用类型。依据网上的一些文章介绍,要了解 C# 对内存的处理,首先要了解 C# 中的变量,以及变量的值是什么。在 C# 中,一个变量仅仅用于连接一个名称(这个名称当然就是变量名了,我们在代码中用到的)和一小块内存。一个变量有它的值,也就是这小块内存中存储的值。至于这小块内存的大小,以及如何解释其 ......