0
我正在C#中創建一個Windows服務,並且在生成的部分類中實現Service
類的dispose方法。如何處理生成的部分類中的處置
像這樣:
partial class Service
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
如何處理處置在這種情況呢?
只有在垃圾回收器接近垃圾回收器之前儘早釋放資源時才處理對象。當服務處置時,它永遠不會有用,GC運行一微秒後。如果您在Designer.cs文件中找到的Dispose()方法實際上不會被調用,那是沒用的。 –
很高興知道,這是fxcop標記的問題,我的公司對這些事情過分教條化。無論如何會造成任何問題嗎?我猜測,如果方法永遠不會被調用。 – ConditionRacer