【发布时间】:2010-11-18 13:55:11
【问题描述】:
我想知道在这种情况下什么时候调用析构函数,如果是,它会在主 UI 线程上调用吗?
假设我有以下代码,什么时候调用析构函数,它会等到我完成所有函数调用吗?
private void Foo()
{
MyObject myObj = new MyObject();
DoSomeFunThingsWithMyObject(myObj);
myObj = new MyObject(); //is the destructor for the first instance called now?
DoLongOminousFunctionality(myObj);
}
//Or will it be called after the DoLongOminousFunctionality?
这只是我感兴趣的事情,如果线程在 myObj = new MyObject() 处被中断,或者如果析构函数调用等待线程空闲。
感谢您的信息。
【问题讨论】:
标签: c# .net destructor