c# - Dispose works fine, but not on terminating -
I have a class that implements However, if I leave the program to end without exposing, I get a Here is the This works fine when: This is when it does not work: Full excetion (no internal exception): Reproduction is 100%, even on different machines. I understand that we should use the The best solution will be IDisposable , because this image resources (
bitmap class) I use it to wrap all the deceptive
lockbits /
unlockbits And it works fine when I use the
Dispose () or
statement statement.
system.exvival exception . Simplicity, I think that GC calls me the
dissection in the same way, and the object releases resources from envy, but it is not what is happening. Why?
IDisposable code:
private bool _disposing = false; ~ QuickBitmap () {remove (wrong); } Public Zero Extraction (Settle (True); GC.SuppressFinalize (this);} Private Wide Dispos (Bull Rifed Decis) {If (_discising) Return; SaveBits (); // UnlockBit Bytes = Private Cover for Null; // byte [] image bmpData = null; // bitmapdata object if (safe Depression & BM! = Tap) {BM.Desc (); // bitmap object BM = null;} _disposing = true;}
using
(var qbm = new QuickBitmap ("myfile.jpg")) {// use qbm.GetPixel Will be on /qbm.SetPixel} < / Pre>
public static zero main (string [] args) {// This is just an example, just create the object and By doing anything, the exception will throw var qbm = new QuickBitmap (args [0]); Qbm.SetPixel (0, 0, Color. Black); qbm.Save ();}
An unrestricted exception of type 'System.AccessViolationException' in mscorlib.Dll Additional Information: Try reading or writing secure memory Ia it was often corrupt an indication that other memory.
use or
() , it is bad to not use it and I just want to know all these things: Why does this happen? Why is memory "protected"? What type of use am I doing? The problem occurs because you included an unnecessary final adder in your implementation. Lastly the code executed Typically can not see managed objects safely, it is likely that calling objects to the
SaveBits are used in violation of this rule, though You did not include the code for that method.
QuickBitmap class
Comments
Post a Comment