有人能帮我看看我的这个秒表程序哪些地方出错吗,谢谢

lechuguilla 2010-11-12 10:19:57
我几乎是抄别人的程序,可添加到我的项目里就错了,这是代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;


namespace iAuto2
{
public class Stopwatch : ModuleBase
{
public Stopwatch()
: base()
{
this.IsVisible = true;
this.id = 32;
}

protected override SimFormBase CreateSelfForm(string Tag)
{
Debug.Assert(this.info != null && this.info.module == this && this.IsModuleRun && this.IsVisible);
Debug.Assert(!this.IsFormRun && this.form == null);
SimFormBase f = new StopwatchForm();
f.Tag = Tag;
return f;
}
}


public class StopwatchForm : SimFormBase
{
private Boolean started = false;
private DateTime dt;
private DateTime dt2;
private Thread time;
private Boolean clear = false;
private SimControlBase m_ctrlDisplay; //秒表数据显示控件


public override void OnCreate()
{
base.OnCreate();

foreach (SimControlBase ctrl in m_Controls)
{
if (ctrl == null)
continue;
//设置菜单分类项目
if (ctrl.Type == SimControlBase.Control_Type.button)
{
ctrl.OnClickEvent += new SimControlBase.SimControlMouseEventHandler(this.BtnCtrlClick);
}

if (ctrl.Name == "Display")
{
ctrl.Text = "00:00:00.000";
m_ctrlDisplay = ctrl;
}
}
}



public override void OnActive()
{
base.OnActive();
Thread time = new Thread(new ThreadStart(timeStart));
time.SetApartmentState(ApartmentState.MTA);
this.OnDeactive();
}

public override void OnDeactive()
{
base.OnDeactive();
this.started = false;
if (time.ThreadState == System.Threading.ThreadState.Suspended)
{
time.Resume();
time.Abort();
}

}


private void BtnCtrlClick(SimControlBase Ctrl, MouseEventArgs e)
{
switch (Ctrl.Name)
{
case "Start":
if (this.started)
{
this.started = false;
Ctrl.BkImageName = "Stop";
time.Suspend();
this.dt2 = DateTime.Now;
}
else
{
this.started = true;
Ctrl.BkImageName = "Start";
if (time.ThreadState == System.Threading.ThreadState.Suspended)
{
if (this.clear)
{
this.dt = DateTime.Now;
this.clear = false;
}
else
{
this.dt = this.dt.AddTicks(DateTime.Now.Ticks - this.dt2.Ticks);
}
time.Resume();
}
else
{
this.dt = DateTime.Now;
time.Start();
}
}
break;
case "Reset":
m_ctrlDisplay.Text = "00:00:00.000asd";
this.clear = true;
break;
case "Exit":
this.Close();
this.Dispose();
break;
}
}

/// <summary>
/// 设置一个代理
/// </summary>
/// <param name="aa"></param>
private delegate void dd(Int64 aa);

private void timeStart()
{
Int64 ms = 0;
while (this.started)
{
Thread.Sleep(1);
ms = DateTime.Now.Ticks - this.dt.Ticks;
SimFormDisp.instance.Invoke(new dd(bb), ms);
}
}

public void bb(Int64 aa)
{
Int64 ms = aa / 10000;//毫秒
int hh = (int)(ms / (1000 * 60 * 60));//时
int mm = (int)((ms % (1000 * 60 * 60)) / (1000 * 60));//分
int ss = (int)((ms % (1000 * 60)) / 1000);//秒
ms = (int)(ms % (1000));//毫秒

m_ctrlDisplay.Text = hh.ToString("00") + ":" + mm.ToString("00") + ":" + ss.ToString("00") + "." + ms.ToString("000");
}
}
}
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
freeboy827 2010-11-17
  • 打赏
  • 举报
回复
解决就好
机器人 2010-11-17
  • 打赏
  • 举报
回复
ft...看了那么长的代码,最后一句是:当晚解决了!!!
下次从下面往上看。。。
lechuguilla 2010-11-17
  • 打赏
  • 举报
回复
当晚解决了
lechuguilla 2010-11-12
  • 打赏
  • 举报
回复
不好意思,我刚才忘说问题了
lechuguilla 2010-11-12
  • 打赏
  • 举报
回复
有很多错误的,
比如我运行的时候就显示private Thread time;这句,time的值永远是null,
wuhuabucai 2010-11-12
  • 打赏
  • 举报
回复
无语 错误都没有
不是每个人都那么闲
csdnflys 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 uncanny 的回复:]
错误提示呢?
[/Quote]
呵呵~~
uncanny 2010-11-12
  • 打赏
  • 举报
回复
错误提示呢?

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧