问个老问题:Timer一直开着如何才不溢出?

s8975565 2010-06-08 03:07:08
如题~ 新人,没分额。。。高手帮看看


private System.Windows.Forms.Timer timer1;

this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

this.timer1.Enabled = true;

...全文
191 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
黑哥 2010-06-08
  • 打赏
  • 举报
回复
确实要注意

上次做个小东西就因为没释放 运行个把小时就OUT了
s8975565 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zzmissll 的回复:]
Bitmap bmp = new Bitmap(img);
你没释放过这个
[/Quote]
谢谢各位了,问题得到解决,是资源没释放的原因~
这里也要释放的。
this.notifyIcon1.Icon.Dispose();
eullarsun 2010-06-08
  • 打赏
  • 举报
回复
TIMER内用到的资源释放就行了。
superwarriors 2010-06-08
  • 打赏
  • 举报
回复
"系统当前时间:"+DateTime.Now.ToString("G");
如果按楼主的做法 为何不用StringBuilder strBuld = new StringBuilder();
strBuld.Append();

这样相对节省内存空间;
blackice8 2010-06-08
  • 打赏
  • 举报
回复
晕死了,一会儿没看回的太晚了.
blackice8 2010-06-08
  • 打赏
  • 举报
回复
timer 怎么溢出的?麻烦把问题讲清楚点儿。
s8975565 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zzmissll 的回复:]
Bitmap bmp = new Bitmap(img);
你没释放过这个
[/Quote]
谢谢 ,去试试~~
zzmissll 2010-06-08
  • 打赏
  • 举报
回复
Bitmap bmp = new Bitmap(img);
你没释放过这个
s8975565 2010-06-08
  • 打赏
  • 举报
回复

private Icon GetIcon(int no)
{
Icon ico = null;
if (no < 4)
{
Image img = imageList1.Images[no];
Bitmap bmp = new Bitmap(img);
ico = Icon.FromHandle(bmp.GetHicon());
}
else
MessageBox.Show("超出ImageList图片的索引!");
return ico;
}
//变色
int i = 1;
private void timer3_Tick(object sender, EventArgs e)
{
if (i == 1)
{
this.notifyIcon1.Icon = GetIcon(i);
i--;
}
else
{
this.notifyIcon1.Icon = GetIcon(i);
i++;
}
}
Jellyfancy 2010-06-08
  • 打赏
  • 举报
回复
把interval属性设成最大就好了。。
好像是2147483647
呵呵
s8975565 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 whoami333 的回复:]
在下一次动作执行之前释放timer代码块中使用的资源。
[/Quote]

string hour = System.DateTimeOffset.Now.Hour.ToString();
string minute = System.DateTimeOffset.Now.Minute.ToString();
string second = System.DateTimeOffset.Now.Second.ToString();
lblTime.Text = "现在时间:"+hour +":"+minute+":"+second;

Timer 是一只开着的,释放掉不是时间就停了?
deknight 2010-06-08
  • 打赏
  • 举报
回复
与timer无关吧,看你timer里执行什么了
zzmissll 2010-06-08
  • 打赏
  • 举报
回复
timer本身不会溢出,你丫关键代码不贴。这些贴了有什么用。
whoami333 2010-06-08
  • 打赏
  • 举报
回复
在下一次动作执行之前释放timer代码块中使用的资源。
s8975565 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 deknight 的回复:]
???哪有溢出
[/Quote]
比方你的程序里用到 Timer 而且 Timer 的 Enabled 属性一直为True 大约1个小时后就溢出了~
s8975565 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 foxdave 的回复:]
Timer中用到的资源及时释放
[/Quote]
能不能说的具体点。
deknight 2010-06-08
  • 打赏
  • 举报
回复
???哪有溢出
Justin-Liu 2010-06-08
  • 打赏
  • 举报
回复
Timer中用到的资源及时释放

111,094

社区成员

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

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

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