Skip to content

Instantly share code, notes, and snippets.

@luisxkimo
Created March 25, 2014 17:56
Show Gist options
  • Select an option

  • Save luisxkimo/9767420 to your computer and use it in GitHub Desktop.

Select an option

Save luisxkimo/9767420 to your computer and use it in GitHub Desktop.
Example StackOverFlowException to test Dispose event
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