-
c#队列使用示例
【实例简介】:一个.NET自带的队列框架。按照先进选出的规则进行数据入队及出队处理。特别适合于改进某些扫表进行数据处理的场合,
- 2021-08-07 00:30:58下载
- 积分:1
-
C# 制作系统服务 实例源码下载
附件中有详细的安装使用文档,大概步骤如下:1.新建Windows项目,选择"Windows服务"类型的工程。2.生成的Program.cs文件中,定义了服务启动的Main函数。 代码 namespace WindowsService1{ static class Program { /// /// 应用程序的主入口点。 /// static void Main() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } }} 3.在新建的工程中,点击Service1.cs文件,切换到代码视图,生成的代码继承于ServiceBase基类,并重载了OnStart和OnStop方法。我在这个文件中进行了一些简单的操作,就是在服务开始的时候,定义一个定时器,然后每隔1秒钟,向文件中写入当前时间。 代码 namespace WindowsService1{ public partial class Service1 : ServiceBase { Timer timer; public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { timer = new Timer(1000); timer.Elapsed = new ElapsedEventHandler(timer_Elapsed); timer.Start(); } protected override void OnStop() { timer.Stop(); timer.Dispose(); } void timer_Elapsed(object sender, ElapsedEventArgs e) { string filePath = AppDomain.CurrentDomain.BaseDirectory "test.txt"; StreamWriter sw = null; if (!File.Exists(filePath)) { sw = File.CreateText(filePath); } else { sw = File.AppendText(filePath); } sw.Write("访问时间:" DateTime.Now.ToString() Environment.NewLine); sw.Close(); } }}4.向工程中添加一个安装程序类。 4.在新添加的安装程序类中,设定服务的名称,启动方式,账号名和密码等信息。 代码 namespace WindowsService1{ partial class Installer1 { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; private System.ServiceProcess.ServiceProcessInstaller spInstaller; private System.ServiceProcess.ServiceInstaller sInstaller; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { components = new System.ComponentModel.Container(); // 创建ServiceProcessInstaller对象和ServiceInstaller对象 this.spInstaller =new System.ServiceProcess.ServiceProcessInstaller(); this.sInstaller = new System.ServiceProcess.ServiceInstaller(); // 设定ServiceProcessInstaller对象的帐号、用户名和密码等信息 this.spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.spInstaller.Password = null; this.spInstaller.Username = null; // 设定服务的名称 this.sInstaller.ServiceName = "WindowsService1"; //设定服务启动的方式 this.sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic; this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.spInstaller,this.sInstaller}); } #endregion }}5.生成工程,在bin目录下会生成exe文件。如果直接运行exe文件的话,是不能执行的,需要使用安装Windows服务用到一个名为InstallUtil.exe的命令行工具,打开命令行工具,转到InstallUtil.exe的目录下,我安装的是VS 2010,对应的目录为:C:WindowsMicrosoft.NETFrameworkv4.0.30319InstallUtil.exe,然后执行InstallUtil.exe 待执行的exe文件的目录,如:InstallUtil.exe F:MyProjectWindowsService1WindowsService1inDebugWindowsService1.exe。执行成功后,会在Windows的服务中,出现了刚刚添加的服务的名称。 6.启动该服务,这时打开binDebug文件夹,发现已经生成了一个test.txt的文件,里面记录了时间。这说明服务已经正式开始执行。7.停止服务的操作也和简单,打开命令行工具,转到C:WindowsMicrosoft.NETFrameworkv4.0.30319目录,然后执行InstallUtil.exe - u F:MyProjectWindowsService1WindowsService1inDebugWindowsService1.exe命令就可以了。
- 2015-04-21下载
- 积分:1
-
winform 图片 全屏 自动播放 实例源码下载
winform 图片 全屏 自动播放 实例源码下载
- 2016-12-03下载
- 积分:1
-
PHP中的 dateline 转换成 c#中的 datetime 方法 UNIX时间转换
在众多的PHP MySQL的应用之中,存储在MySQL中的时间都是一串数字,后经查这个格式的日期叫做:Unix Timestamp;Unix的timestamp是一组数字,表示从1970年1月1日以来的秒数。今天在进行C#应用开发时需要对MySQL中的数据进行操作,写出以下方法供大家参考。主要应用到的类库有:System.TimeZone应用的方法:返回对应于指定协调通用时间 (UTC) 的本地时间。public virtual DateTime ToLocalTime( DateTime time);1、将系统时间转换成UNIX时间戳 DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)); DateTime dtNow = DateTime.Parse(DateTime.Now.ToString()); TimeSpan toNow = dtNow.Subtract(dtStart); string timeStamp = toNow.Ticks.ToString(); timeStamp = timeStamp.Substring(0,timeStamp.Length - 7); 2、将UNIX时间戳转换成系统时 string timeStamp = "1176686120"; DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)); long lTime = long.Parse(timeStamp "0000000"); TimeSpan toNow = new TimeSpan(lTime); DateTime dtResult = dtStart.Add(toNow);
- 2013-11-14下载
- 积分:1
-
思维导图(C++ Primer Plus(第六版).xmind)
思维导图(C++ Primer Plus(第六版).xmind)
- 2020-12-06下载
- 积分:1
-
枚举所有QQ窗口(C#调API)
枚举所有QQ窗口(C#调API)
- 2014-06-22下载
- 积分:1
-
XML学习
public Turntable() { InitializeComponent(); int angle = 5029; for (int i = 0; i < 16; i ) { angle = 22; _ListAngle.Add(angle); } } /// /// 保存八个角度 /// List _ListAngle = new List(); /// /// 产生随机数 /// Random _Random = new Random(); int _Index = 0; int _OldAngle = 0; private void btnStartTurntable_Click(object sender, RoutedEventArgs e) { btnStartTurntable.IsEnabled = false; _Index = _Random.Next(0, 16); //_Index = 2; Storyboard sb = (Storyboard)this.FindResource("zhuandong"); sb.Completed -= this.sb_Completed; sb.Completed = new EventHandler(sb_Completed); ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[0]).Value = _OldAngle; ((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[3]).Value = _ListAngle[_Index]; //((SplineDoubleKeyFrame)((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[3]).Value = 5218; sb.Begin(); } void sb_Completed(object sender, EventArgs e) { DispatcherTimer dt = new DispatcherTimer(); dt.Interval = TimeSpan.FromSeconds(0.3); dt.Tick = delegate { dt.Stop(); _OldAngle = (_ListAngle[_Index] % 360); btnStartTurntable.IsEnabled = true; AwardProcess(GetAward(_ListAngle[_Index])); }; dt.Start(); } public delegate void AwardDelegate(Award award); /// /// 返回转到的奖项信息 /// public event AwardDelegate AwardProcess; private Award GetAward(int angle) {
- 2014-08-01下载
- 积分:1
-
QQ的屏幕截图程序
QQ的屏幕截图程序
- 2015-11-15下载
- 积分:1
-
opencvsharp 打开图像并且使用WPF中Image显示
实现用opencvsharp打开图像,并且使用Image显示,其中包括Mat类型的转换方法。
- 2020-12-04下载
- 积分:1
-
asp.net网站实现类似timer的定时任务
asp.net网站实现类似timer的定时任务
- 2015-05-01下载
- 积分:1