J
JollyK
Hello everyone,
I have a abstract class called DalBase and in that class I have a couple of
methods. One of the method that I have is called BeginTran() and this class
initializes a private Transaction object. I also have a method called
CommitTran() that disposes the private Transaction object, thus setting it
to null. Now the issue is, if the user calls BeginTran, I have to make sure
he/she calls CommitTran() so that the private transaction object gets set to
null. The only way I can think of is using C# distructor.
So I have coded
Now I have checked when I run the application, and call BeginTran() method
and intentionally not call CommitTran(), the above code does not get
executed. But if I set a break point at the above code, then it gets
executed. This is probably something to do with garbage collection. But how
do I solve the problem I am having. A short example would be very helpful.
Thanx alot
I have a abstract class called DalBase and in that class I have a couple of
methods. One of the method that I have is called BeginTran() and this class
initializes a private Transaction object. I also have a method called
CommitTran() that disposes the private Transaction object, thus setting it
to null. Now the issue is, if the user calls BeginTran, I have to make sure
he/she calls CommitTran() so that the private transaction object gets set to
null. The only way I can think of is using C# distructor.
So I have coded
Code:
~DalBase()
{
if (this._transaction != null)
{
throw (new Exception("You have opened a transaction that needs to be
closed."));
}
}
Now I have checked when I run the application, and call BeginTran() method
and intentionally not call CommitTran(), the above code does not get
executed. But if I set a break point at the above code, then it gets
executed. This is probably something to do with garbage collection. But how
do I solve the problem I am having. A short example would be very helpful.
Thanx alot