Ejemplo n.º 1
0
        public ExceptionSafe()
        {
            PreciousResource tmp1 = null, tmp2 = null;

            try
            {
                tmp1 = new PreciousResource();
                tmp1.Open();
                tmp2 = new PreciousResource();
                tmp2.Open();

                // Commit point, no exception risk any more.
                resource1 = tmp1;
                tmp1      = null;
                resource2 = tmp2;
                tmp2      = null;
            }
            finally
            {
                if (tmp1 != null)
                {
                    tmp1.Dispose();
                }

                if (tmp2 != null)
                {
                    tmp2.Dispose();
                }
            }
        }
 public void Dispose()
 {
     resource.Dispose();
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     resource1.Dispose();
     resource2.Dispose();
 }