| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 876 人关注过本帖
标题:如何添加 Timers 类?
只看楼主 加入收藏
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
收藏
 问题点数:0 回复次数:3 
如何添加 Timers 类?
我在代码中 使用 using System.Timers;添加Timers类,但是编译却出现错误,
F:\Program_Files\Microsoft Visual Studio .NET 2003\mywork\ConApp5\Class1.cs(4): 类型或命名空间名称“Timers”在类或命名空间“System”中不存在(是否缺少程序集引用?)如附件所示

不知道除了在代码中这样编辑之外,还要在哪里设置才能正确添加呢?

Timers.JPG (28.19 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: Timers 定时器 
2008-08-08 01:12
fjfhnui
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-6-18
收藏
得分:0 
TIMERS 是什么玩意啊
2008-08-11 00:01
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
MSDN帮助文件中的一个示例
//-----------------------------------------------------------------------
//  This file is part of the Microsoft .NET Framework SDK Code Samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//This source code is intended only as a supplement to Microsoft
//Development Tools and/or on-line documentation.  See these other
//materials for detailed information regarding Microsoft code samples.
//
//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//
/*=====================================================================
  File:      TimedCallback.cs

  Summary:   Demonstrates the use of the Timer class to generate a
             periodic callback to a method.

=====================================================================*/

using System;
using System.Threading;


class App
{
    public static void Main()
    {
        Console.WriteLine("Checking for status updates every 2 seconds.");
        Console.WriteLine("   (Hit Enter to terminate the sample)");
        Timer timer = new Timer(new TimerCallback(CheckStatus), null, 0, 2000);
        Console.ReadLine();
        timer.Dispose();
    }


    // The callback method's signature MUST match that of a System.Threading.TimerCallback
    // delegate (it takes an Object parameter and returns void)
    static void CheckStatus(Object state)
    {
        Console.WriteLine("Checking Status.");
        // ...
    }
}
2008-08-14 11:56
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
回复 2# fjfhnui 的帖子
System.Windows.Forms.Timer是应用于WinForm中的,它是通过Windows消息机制实现的,类似于VB或Delphi中的Timer控件,内部使用API     SetTimer实现的。它的主要缺点是计时不精确,而且必须有消息循环,Console     Application无法使用。      
     
  System.Timers.Timer和System.Threading.Timer非常类似,它们是通过.NET     Thread     Pool实现的,轻量,计时精确,对应用程序、消息没有特别的要求。System.Timers.Timer还可以应用于WinForm,完全取代上面的 Timer控件。它们的缺点是不支持直接的拖放,需要手工编码。      
   
  推荐使用System.Timers.Timer,代码这个地方有,自己读读就好.  
  ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemtimerstimerclasstopic.htm
2008-08-14 12:08
快速回复:如何添加 Timers 类?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030236 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved