All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
关于.NET脏字过滤的算法代码_.net资料_编程技术
用VB.NET,2005编写定时关机程序_.net资料_编程技术
ASP.NET中动态控制RDLC报表_[Asp.Net教程]
规范设计数据库应注意的14个技巧_[SQL Server教程]
让GridView有新增记录的功能_[Asp.Net教程]
X-Space:日志发布后首页为何不更新-_php资料_编程技术
ASP.NET之上传文件管理策略_.net资料_编程技术
VS2005+SQL2005,ASP.NET2.0数据库连接_.net资料_编程技术
ClassWizard的简单应用
ASP.NET,Atlas简单控件介绍之界面控件_[Asp.Net教程]
Reading number is top 10 pictures
Embarrassing things comic collection1
Entered the goddess in the AD1
红楼梦金陵十二钗(2)
A man's favorite things16
NeedWallpaper4
这才是真正的人体艺术2
Sora aoi possession photo2
The real super beauty13
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
China railway shunting skills competition
Download software ranking
matrix1
Tram sex maniac 2 (H) rar bag3
Unix video tutorial9
功夫熊猫2(下集)
Desire a peach blossom
Tram sex maniac 2 (H) rar bag15
网络管理员第三版
DreamWeaver8
C++教程第四版
WebService在.NET中的实战应用教学视频 → 第2集
delv published in(发表于) 2014/1/27 6:50:17 Edit(编辑)
VS2005开发中Timer控件失效的解决方法_[Asp.Net教程]

VS2005开发中Timer控件失效的解决方法_[Asp.Net教程]

VS2005开发中Timer控件失效的解决方法_[Asp.Net教程]

本文介绍了使用VS2005进行开发时Timer控件失效的解决方法,大家在实际开发过程中可以参考一下……


  Timer控件失效的解决


  在Windows 服务不引发计时器事件


  原因:


  我认为windows服务里不能使用System.Windows.Forms的Timer控件,Windows.Forms 计时器组件用于 Windows.Forms 环境。WindowsForms 计时器组件不用于服务器环境,所以要使用System.Timer下的控件。


  解决方案


  这个可以通过修改控件的类型,把所有使用服务器计时器从命名空间 System.Timers 代替 System.Windows.Forms 计时器。如:


Service1.Designer.cs
  1namespace MyNewService
  2{
  3 partial class MyNewService
  4 {
  5 /**////
  6 /// 必需的设计器变量。
  7 ///
  8 private System.ComponentModel.IContainer components = null;
  9
  10 /**////
  11 /// 清理所有正在使用的资源。
  12 ///
  13 /// 如果应释放托管资源,为 true;否则为 false。
  14 protected override void Dispose(bool disposing)
  15 {
  16 if (disposing && (components != null))
  17 {
  18 components.Dispose();
  19 }
  20 base.Dispose(disposing);
  21 }
  22
  23 组件设计器生成的代码#region 组件设计器生成的代码
  24
  25 /**////
  26 /// 设计器支持所需的方法 - 不要
  27 /// 使用代码编辑器修改此方法的内容。
  28 ///
  29 private void InitializeComponent()
  30 {
  31 this.eventLog1 = new System.Diagnostics.EventLog();
  32 this.timer1 = new System.Timers.Timer();
  33 ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
  34 ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
  35 //
  36 // timer1
  37 //
  38 this.timer1.Interval = 2000;
  39 this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
  40 //
  41 // MyNewService
  42 //
  43 this.CanPauseAndContinue = true;
  44 this.CanShutdown = true;
  45 this.ServiceName = "MyNewService";
  46 ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
  47 ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
  48
  49 }
  50
  51 #endregion
  52
  53 private System.Diagnostics.EventLog eventLog1;
  54 private System.Timers.Timer timer1;
  55
  56 }
  57}Service1.cs:
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Diagnostics;
  6using System.ServiceProcess;
  7using System.Text;
  8
  9namespace MyNewService
  10{
  11 public partial class MyNewService : ServiceBase
  12 {
  13 public MyNewService()
  14 {
  15 InitializeComponent();
  16 if (!System.Diagnostics.EventLog.SourceExists("MySource"))
  17 {
  18 System.Diagnostics.EventLog.CreateEventSource(
  19 "MySource", "MyNewLog");
  20 }
  21 eventLog1.Source = "MySource";
  22 eventLog1.Log = "MyNewLog";
  23 }
  24
  25 protected override void OnStart(string[] args)
  26 {
  27 eventLog1.WriteEntry("In OnStart");
  28 this.timer1.Enabled = true;
  29
  30
  31 }
  32
  33 protected override void OnStop()
  34 {
  35 eventLog1.WriteEntry("In onStop.");
  36 this.timer1.Enabled = false;
  37 }
  38
  39 protected override void OnContinue()
  40 {
  41 eventLog1.WriteEntry("In OnContinue.");
  42 }
  43
  44
  45
  46 private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  47 {
  48 eventLog1.WriteEntry("timer1_Tick." + DateTime.Now.ToString());
  49 }
  50
  51
  52 }
  53}


出处:中国自学编程网






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.