Code snippet to implement IDisposable
1~DemoType ()2 {3 This. Dispose ();4 }5 6 #regionIDisposable Members7 8 /// <summary>9 ///Internal variable which checks if Dispose has already been calledTen /// </summary> One protectedBoolean disposed; A - /// <summary> - ///releases unmanaged and-optionally-managed resources the /// </summary> - /// <param name= "disposing" ><c>true</c>To release both managed and unmanaged resources;<c>false</c>To release only unmanaged resources.</param> - protected voidDispose (Boolean disposing) - { + if(disposed) - { + return; A } at - if(disposing) - { - //todo:managed Cleanup code here, while Managed refs still valid - } - //todo:unmanaged Cleanup Code here in -disposed =true; to } + - /// <summary> the ///performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. * /// </summary> $ Public voidDispose ()Panax Notoginseng { - //Call the private Dispose (bool) helper and indicate the //That we is explicitly disposing + This. Dispose (true); A the //Tell the garbage collector, the object doesn ' t require any + //cleanup when collected since Dispose is called explicitly. -Gc. SuppressFinalize ( This); $ } $ - #endregion
Common Code Snippets