【发布时间】:2013-11-19 14:09:50
【问题描述】:
故事的开始是here。
我有一个组件,我希望它清理计时器(托管资源,对吗?):
public class MyPictureBox : PictureBox, IDisposable
{
private Timer _timer1 = new Timer();
private Timer _timer2 = new Timer();
public MyPictureBox(): base()
{
_timer1.Interval = 100;
_timer1.Start();
_timer2.Interval = 250;
_timer2.Start();
}
// ... all sort of code
new void Dispose()
{
base.Dispose();
_timer1.Dispose();
_timer2.Dispose();
}
void IDisposable.Dispose()
{
_timer1.Dispose();
_timer2.Dispose();
}
}
如您所见,我尝试再实现一个(oO)IdDisposable(尽管 PictureBox->Control->Component->IDisposable)。但是..它们都没有被调用。
使用设计器将控件置于表单上。但它没有出现在表单Components 中,这应该是在处理表单时不调用它的原因:
Form1 form = new Form1();
form.Dispose(); // MyPictureBox.Dispose() are not called
我的问题是我应该如何组织处置我的控制计时器以获得我需要的东西 - 处置 MyPictureBox 计时器和表单处置?
【问题讨论】:
标签: c# winforms controls dispose