Mike9900 <Mi******@discussions.microsoft.com> wrote:
We need to know the module that called the other module in that module.
For example, StartMyTransaction module,is called by module 'A' and after
that module 'B' calls EndMyTransaction, but we do not want this module to end
the transaction by calling EndMyTransaction. If we know who called it first
we can the end the transaction when module 'A' calls EndMyTransaction.
If I know who called the StartMyTransaction first, then I can end it when
module 'A' calls EndMyTransaction. What is the best way?
You're using this as a run-time sanity-check, yes? To make sure that
the transaction is ended by the same person who started it?
Then wrap it up inside an object, so that correctness is guaranteed by
object-identity:
public class Transaction
{ public Transaction() {StartMyTransaction();}
public void Close() {EndMyTransaction();}
}
That way, module A does
Transaction t = new Transaction();
to start a transaction, and it does
t.Close();
to end the transaction. And it's impossible for module'B' to end the
transaction unless the transaction has been given to 'B' by 'A'.
--
Lucian