Created
March 25, 2014 17:56
-
-
Save luisxkimo/9767420 to your computer and use it in GitHub Desktop.
Example StackOverFlowException to test Dispose event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyObject : IDisposable | |
| { | |
| public string id; | |
| public MyObject(string id, bool throwException) | |
| { | |
| if (throwException) | |
| { | |
| //Environment.Exit(100); | |
| Recursive(1000); | |
| } | |
| else | |
| { | |
| this.id = id; | |
| Console.WriteLine("Objecto {0} construido ", id); | |
| } | |
| } | |
| public void Dispose() | |
| { | |
| Console.WriteLine("Dispose {0}", id); | |
| } | |
| static void Recursive(int value) | |
| { | |
| Recursive(++value); | |
| } | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| using (MyObject obj1 = new MyObject("Uno", false), obj2 = new MyObject("Dos", true)) | |
| { | |
| Console.WriteLine("Hemos entrado en el using"); | |
| } | |
| Console.ReadLine(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment