using System;
using System.Timers;class myApp
{
public static void Main()
{
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
myTimer.Interval = 1000;
myTimer.Start(); while (Console.Read() != 'q')
{
; //do nothing...
Console.WriteLine("----------------------------");
}
}
public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
Console.Write("\r{0}", DateTime.Now);
}
}我的问题就是Console.WriteLine("----------------------------"); 当定时器计时的时候,输入"q"以外的字母While会循三次Console.WriteLine("----------------------------"); 为什么呢?
using System.Timers;class myApp
{
public static void Main()
{
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
myTimer.Interval = 1000;
myTimer.Start(); while (Console.Read() != 'q')
{
; //do nothing...
Console.WriteLine("----------------------------");
}
}
public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
Console.Write("\r{0}", DateTime.Now);
}
}我的问题就是Console.WriteLine("----------------------------"); 当定时器计时的时候,输入"q"以外的字母While会循三次Console.WriteLine("----------------------------"); 为什么呢?
解决方案 »
- .NET的高手们,.net framework 2.0如何精简到最小并能支持你的软件?
- TCP监听程序,如何实现停止监听时释放所用的端口?
- 关于messagebox窗口的问题
- 为什么VS2005的断点停不下来
- 资源释放:无法复制XXX:文件正在被另一个人或程序使用。关闭任何可能使用这个文件程序,重新试一次。
- 非常急,使用OpenNETCF.Net的ConnectToPreferredNetwork方法连接wifi成功,但是一段时间后自动关闭
- 简单的饭店项目(菜鸟征集想法,有满意的方案,马上给分^_^)
- 如何在C#中使用win32 C++库中API函数??
- 在c#中url中的参数为中文取道是乱码,该如何处理????
- 请问怎样在 DataGrid 的 HyperLinkColumn 里面绑定多个参数
- c# 数据保存
- 【用户登陆】C#写的用户登录窗体(与数据库连接),谁帮我看看出什么问题了
三次:keydown,keypress,keyup,应该是这三次了
这样你敲一个q,读入的是"q/r/n",最后两个是换行和回车,所以就有问题了楼主可以用Console.ReadKey(),判断语句这样写while (Console.ReadKey() != Keys.Q)
using System.Timers; class myApp
{
public static void Main()
{
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
myTimer.Interval = 1000;
myTimer.Start(); while (Console.ReadKey().KeyChar!= 'q')
{
; //do nothing...
Console.WriteLine("----------------------------");
}
}
public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
Console.Write("\r{0}", DateTime.Now);
}
}