Strange ... very strange ...
Perhaps the article is incorrect. The using statement compiled exactly like
MyDisposableObject obj = new MyDisposableObject() try { obj.Use(); } finally { if (obj!=null) obj.Dispose(); }
The Dispose method is explicitly called in the finally block, unlike the / Finalize destructor method, which is called before the collection, but at the discretion of GC.
I think this is a mistake in the article. At best ... something could mean scheduling threads. If the CLR decides to schedule other threads, once clicking finally, then you can wait a bit of time on the 100% CPU load and higher priority tasks started to run Dispose.
It is important for Dispose to be synchronous !!! Think About This Managed Resource Example
public void Log(string message) { using(StreamWriter sw = new StreamWriter(File.Append(path))) { sw.WriteLine(message); } } public static void Main() { Log("Hello"); Log("World"); }
Calling Dispose , in streams and files, actually closes them. If what was written in the article was true, you would call the second Log with an open file , thereby immediately raising an IOException !
usr-local-ΞΞ¨ΞΞΞΞ©Ξ
source share