473,408 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Finding the caller name

Hello,

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?

Mike
Apr 9 '06 #1
2 1319
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
Apr 9 '06 #2
Here is what the code may look like:

public static Main()
{
A a=new A()
a.DoActionA();
}
public sealed class MyTrans
{
public static StartMyTransaction(){}
public static EndMyTransaction(){}
}

public class A
{
public DoActionA()
{
MyTrans.StartMyTransaction();
///Do some actions
B b=new B();
b.DoActionB();//We are calling b from a, but B must not do anything with
the transaction, not it must give exception
MyTrans.EndMyTransaction();
}
}
public class B{
public DoActionB()
{
MyTrans.StartMyTransaction();///Cannot do it, reutns without error
///Do some actions
MyTrans.EndMyTransaction();//Cannot do it, reutns without error
}
}

--
Mike
"Lucian Wischik" wrote:
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

Apr 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Abrahams | last post by:
Is there any way to determine the file and line number (if any) of a method's invocation from within its body? Many Thanks in advance, Dave -- David Abrahams Boost Consulting...
9
by: jaden10001 | last post by:
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there a way to get the name of the caller of a function in Opera 7?
4
by: Pekka Henttonen | last post by:
Let's say there is an object which has several methods all taking different object as argument: class TestObject { public void SetTitle( TitleObject title ); public void SetDate( DateObject...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
6
by: Derek Peschel | last post by:
Here are two functions. def invert_dict_to_lists(dict): lists = {} for key in dict: value = dict if not value in lists: lists = else: lists.append(key)
5
by: pamelafluente | last post by:
Hi guys, How do I get the full name of the current (overload) function or sub (whatever it be) ? Sub SomeFunction() Dim FullNameOfThisFunction = ??? msgbox(FullNameOfThisFunction )
3
by: Rico | last post by:
Hello, I have a generic process that logs errors from different sources. When I call this code, I'd like to also submit the name of the function or sub that is raising the error without having...
3
by: Francesco Guerrieri | last post by:
Hi, Today I've been thinking a bit about the "python internals". Inspired by this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062 I found out a little problem which...
9
by: Erwin Moller | last post by:
Hi all, Is it possible (PHP5.2) to find the name of a variable used in the caller of a function from within the function itself? Or to be more clear: ...php code.. $result = foo($abc);...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.