我写了两个在main入口的方法.为什么只能执行第一个.有没有办法让两个都执行!谢谢
我的程序为什么只能执行第一个方法?
using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Timer tmr = new Timer(new TimerCallback(DoTimer), null, 0, 900000); Console.Read(); Timer tmr1 = new Timer(new TimerCallback(DoTimer1), null, 0, 1200000); Console.Read(); } static void DoTimer(object state) { //do something } static void DoTimer1(object state) { //do something } } }
我的程序为什么只能执行第一个方法?
using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Timer tmr = new Timer(new TimerCallback(DoTimer), null, 0, 900000); Console.Read(); Timer tmr1 = new Timer(new TimerCallback(DoTimer1), null, 0, 1200000); Console.Read(); } static void DoTimer(object state) { //do something } static void DoTimer1(object state) { //do something } } }
解决方案 »
- 怎样定义接口或是抽象出接口来
- 定义枚举 怎么在Grid中显示出来~
- 想搞明白程序 从代码到可运行的原理。 包括 跨平台时不能运行的原因。
- 如何修改窗体和窗体中控件的字体大小?
- Web工程中页面刷新而自定义控件不刷新
- 谁有访问lotus notes数据库的类给我发一个[email protected]
- 如何把 单位为"缇"的值 转换为 像素 的值
- 我刚学C#请各位帮帮忙
- 讨论:面向对象的程序设计在数据库编程中的效率问题,欢迎投稿,来者有分
- 要对device表的所有记录的count字段值加20 该怎么写SQL 急急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- DataGridViewComboxCell tag属性的赋值问题?????????????
- 如何将设备相关位图转化为设备无关位图?
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Timer tmr = new Timer(new TimerCallback(DoTimer), null, 0, 900000);
Console.Read();
Timer tmr1 = new Timer(new TimerCallback(DoTimer1), null, 0, 1200000);
Console.Read();
}
static void DoTimer(object state)
{
//do something
}
static void DoTimer1(object state)
{
//do something
}
}
}
他说的不是两个main方法,是两个回调:TimerCallback!
楼主这代码写得,没话说!
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Timer tmr = new Timer(new TimerCallback(DoTimer), null, 0, 900000);
Timer tmr1 = new Timer(new TimerCallback(DoTimer1), null, 0, 1200000);
Console.Read();
}
static void DoTimer(object state)
{
//do something
}
static void DoTimer1(object state)
{
//do something
}
}
}
多線程類:
System.Threading.Thread
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Timer tmr = new Timer(new TimerCallback(DoTimer), null, 0, 900000);
// Console.Read();
Timer tmr1 = new Timer(new TimerCallback(DoTimer1), null, 0, 1200000);
Console.Read();
}
static void DoTimer(object state)
{
//do something
}
static void DoTimer1(object state)
{
//do something
}
}
}
如何改进呀.我以都是写的asp.net方面的.对这winform实在是不行
Console.Read();
程序已经可以执行下一个.但是只有执行第一个后才能执行第二个.能不能同时执行这个呀?
你如何知道第二个一定是在第一个方法完全执行完毕后才启动的呢?
建议你在两个方法里的第一行前和最后一行后加两个语句:Console.WriteLine("《方法名》started");和Console.WriteLine("《方法名》Ended"); 然后看看这两对语句的输出是否“交叉”!
当然,基于你的这段代码,不用看也知道不会“交叉”,原因很简单:看看你两个timer的间隔时间吧,一个900秒,另一个1200秒,什么概念?有什么方法在300秒内还执行不完呢?