kikapu,
The TransactionScope class will only work on resources that register
themselves with the transaction mananger. Right now, the most immediate
example of a resource like this is a database. It doesn't automatically
just detect changes to anything in the scope and then roll them back if
Complete is not called.
However, it is possible to have local variables which are rolled back in
the event of an abort of a transaction. Check out the article by Juval Lowy
titled "Volatile Resource Managers in .NET Bring Transactions to the Common
Type", as it provides a mechanism by which to do this:
http://msdn.microsoft.com/msdnmag/is.../Transactions/
Of course, you shouldn't do this for ALL of your variables (that will be
a huge performance hit), but for the ones that you need rolled back in the
case of an abort.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"kikapu" <me******@newsgroups.nospamwrote in message
news:ew*************@TK2MSFTNGP03.phx.gbl...
Hi to all folks,
i am trying to understand the use of System.Transactions in general and
TransactionScope particularly.
What am i allowed to do in a using statement that wraps a TransactionScope
object,
so this to be rollback in case of an exception or when i do not call
scope.complete ??
I mean, can i set an object's variables and then un-done these sets
automatically
when transaction rolls back ??
For example, the following code does not work, x.var remains 2 after the
suing statement,
even if i throw an exception after var set:
class Program
{
static void Main(string[] args)
{
X x = new X();
x.var = 1;
using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{
x.var = 2;
//scope.Complete();
}
Console.WriteLine(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??
Kikapu