Skip to content

To identify the Function Caller

Chia Huang

Asked Jul 18, 2006, 2:10 AM EDT2 answers
Share
LinkedInX
Hi all, I'm new to this forum as well as to the language C#. I'm hoping to learn from the experts here.

Ok, this is what I have to do. I need to indentify who calls the function and take corresponding actions to the callers.

To make it more clear, I need to indetify who calls the Dispose() function of a Form. What I need to do is, if the user click on "Quit", which I provide and calls the Dispose() function, on the Form, it disposes the form in one way. However, if the user reboot or shuts down the PC which the From is till running, the OS would call Dispose() also but then I will have to take some other actions when the caller of Dispose function is the OS. So I must determine who's the caller of the dispose function to take corresponding actions.

Any suggestions would be much appreciated. Thanks for you guys' help in advance.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    i'm definitely no expert but this might be worth a try. When you call dispose() from the click event function, you can have it pass an argument to dispose().  If this argument is recieved by  dispose(),  have it follow the procedure you want. Otherwise execute the other code.  I dont know how this will work since the OS wont pass an argument.  Im not even sure if the OS would call dispose(). it might just terminate the program.  Like i said i am not an expert.  But it might be worth a try.
    0
  • 0
    Dale, that was a good solution and also was the first thing I tried. However, by doing that, I face another problem: the X close button on the upper right hand corner of the form calls the same Dispose as the OS does. And what I have to do is to separate OS's calling of dispose from all other callings...hope I made that clear enough. Anyways, thanks a lot.
    0