問題排查:沒有任何多載符合 System.Timers.ElapsedEventHandler 委派
這是在實作當前專案最後一個關鍵功能:提醒通知
所遇到的奇怪狀況
目前的設想,是以 Windows Form 結合 Timer,當作發送通知的載體
大家都知道在 C# 的環境裡,有三種內建的 Timer 可用:Windows Form Timer、System.Timer、Threading.Timer
遇到的怪事,主要是在 System.Timer 這一段
代碼如下:
using System;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms; namespace SystemTimer
{
public partial class Form1 : Form
{
int number = ;
DateTime dt1 = new DateTime();
DateTime dt2 = new DateTime(); System.Timers.Timer tm; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void b1_Click(object sender, EventArgs e)
{
tm = new System.Timers.Timer();
tm.Interval = ;
tm.Enabled = true;
tm.Elapsed += new System.Timers.ElapsedEventHandler(tm_elapsed);
tm.Start();
dt1 = DateTime.Now;
} private void b2_Click(object sender, EventArgs e)
{
tm.Enabled = false;
dt2 = DateTime.Now;
MessageBox.Show(Convert.ToString(dt2 - dt1));
} private void tm_elapsed(object sender, System.Timers.ElapsedEventHandler e)
{
lbmsg.Text = Convert.ToString(++number);
Thread.Sleep();
}
}
}
編譯時在標示紅色的那行提示錯誤,來對照一下微軟的官方參考資料
回調函數原形
public delegate void ElapsedEventHandler(
Object sender,
ElapsedEventArgs e
)
所以只要把
private void tm_elapsed(object sender, System.Timers.ElapsedEventHandler e)
{
lbmsg.Text = Convert.ToString(++number);
Thread.Sleep();
}
改成
private void tm_elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lbmsg.Text = Convert.ToString(++number);
Thread.Sleep();
}
就可以了
問題排查:沒有任何多載符合 System.Timers.ElapsedEventHandler 委派的更多相关文章
- 問題排查:行動裝置網頁前端 UI 設計 (1)
這是最近開始接手的一個微信公眾平台專案, 在重整後端程式碼時,因為也需要透過前端來看效果, 所以就因此在前端的部分遇到了不少問題, 畢竟這是以前沒接觸過的領域 (早年的網頁應用程式開發沒有那麼多分工) ...
- 問題排查:DataGridView 資料行下拉選單,資料繫結階段顯示 DataGridViewComboBoxCell 值無效
可能原因: 1.下拉選單的選項資料繫結晚於 DataGridView 的資料繫結 2.下拉選單的 DataPropertyName 屬性,比 DisplayMember.ValueMember 早賦值 ...
- 問題排查:在 ServiceModel 客戶端配置部份中,找不到名稱 和協定 的終結點元素。
同樣都是刪掉服務參考再重建重編譯重發行,為什麼之前幾次都沒事? 這次只不過是刪掉服務參考,然後換了個名稱重建而已,做完就變這樣? 後來發現問題出在 app.config,因為之前 app.config ...
- 問題排查:行動裝置網頁前端 UI 設計 (2)
之前上網找了個星級評分的範例來玩, 當然這個範例已經用在另一個專案了, 目前看起來沒什麼狀況, 不過在移植到目前的專案之後, 就出現了怪現象: 1. 在大部份時間裡,點擊星星不會有任何反應 2. 即便 ...
- 問題排查:System.BadImageFormatException: 未能加载文件或程序集“System.ServiceModel
錯誤訊息如下: System.BadImageFormatException: 未能加载文件或程序集“System.ServiceModel, Version=3.0.0.0, Culture=neu ...
- 問題排查:类型“System.DateTime”的对象无法转换为类型“System.String”
最近在擴充資料對接工具的功能 經常會遇到這個狀況 當然還有其他同類提示,例如 int/decimal 無法轉 System.String 等等 無獨有偶 這些錯誤幾乎都是在 DataTable 轉換成 ...
- 問題排查:.NETSystem.Runtime.Remoting.RemotingException: TCP 信道协议冲突: 应为报头。
這個錯誤訊息是在一個 Web Serveice 的偵錯階段發生的 目前還未找到原因,環境如下: 作業系統:Windows 10 x64 企業版 (簡中) 開發工具:Visual Studio 2013 ...
- 問題排查:F5啟動偵錯後所提示的錯誤 (2)
原始專案版本:Visual Studio 2005 開發環境:Visual Studio 2013 偵錯運行環境:IIS Express 啟動偵錯後,錯誤提示內容如下: HTTP 错误 403.14 ...
- 問題排查:F5啟動偵錯後所提示的錯誤 (1)
原始專案版本:Visual Studio 2005 開發環境:Visual Studio 2013 偵錯運行環境:IIS Express 啟動偵錯後,錯誤提示內容如下: HTTP 错误 500.23 ...
随机推荐
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- TIOBE Index for December 2015(转载)
There is hardly any doubt about it, Java will become TIOBE's programming language of the year 2015. ...
- 报错:严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [/index.jsp (line: 13, column: 20) No tag "textfiled" defined in tag library imported with prefix
严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [ ...
- 学习SQL的点点滴滴(二)删除临时表
select into 创建的表属于临时表,判断是否存在的方法 select c_adno,c_con_no into #temp from tb_contract IF OBJECT_ID( 'te ...
- vim全选,全部复制,全部删除
全选(高亮显示):按esc后,然后ggvG或者ggVG 全部复制:按esc后,然后ggyG 全部删除:按esc后,然后dG 解析: gg:是让光标移到首行,在vim才有效,vi中无效 v : 是进入V ...
- python Requests库在处理response时的一些陷阱
python的Requests(http://docs.python-requests.org/en/latest/)库在处理http/https请求时还是比较方便的,应用也比较广泛.但其在处理res ...
- EF 自测例子
public ActionResult Test() { using (MvcShoppingContext db = new MvcShoppingContext()) ...
- Win32API界面库 - Project wheels 工程基础部分完成
离上次发博文过去了好久,先是要忙一个机器人的项目,然后就是部门的事情和考试周复习,然后就到了考试周,趁着复习的间隙,拾起了寒假时候抄的界面库,修掉了从前的bug. bug1 控件显示问题 当初抄这个库 ...
- linux查看磁盘io的几种方法
怎样才能快速的定位到并发高是由于磁盘io开销大呢?可以通过三种方式: 第一种:用 top 命令 中的cpu 信息观察 Top可以看到的cpu信息有: Tasks: 29 total, 1 runnin ...
- the philosophy behind of the design of the STL
The concept of STL is based on a separation of data and operations. The data is managed by container ...