1

ok so writing API to control image viewing system. We have their API in our program. We pickup all the shared events using register events like

context_server.PasswordChange += ContextServer_PasswordChange;

so now I set the password in my code

connector.ContextServer.password = MCrypto.EncryptPasswordAnsi(password);

which makes us fires the event on our side

       void ContextServer_PasswordChange(string Password_string)

so now.. I initiated that call... so when we do that.. the other system changes the password on its side and we see that call happen again...as a response... so right now I have a variable saying WeInitiated=true right before I call some code that will fire each registered event and when it happens I set it to false.. so then when they call I know they initiated it. so looks like this

        void ContextServer_PasswordChange(string Password_string)
    {
        String fn = "ContextServer_PasswordChange: ";

        if (WeInitiated)
        {
            log.Debug(fn + " WeInitiated");
            WeInitiated = false;
        }
        else
        {
            log.Debug(fn + " They Initiated");
        }}

So I'm trying to see if there is a better way to do this.. is there a way to know who initiated the call to the registered event ? FYI.. I'm no pro at registered events.. this is my first time using it..

any insights or tips are appreciated..

kevin_kss
  • 33
  • 4
  • A typical [EventHandler](https://learn.microsoft.com/en-us/dotnet/api/system.eventhandler-1?view=netframework-4.8) would look like `void HandleXEvent( object sender, EventArgs e )` ... is there something similar in the API? – Fildor Apr 22 '20 at 12:49
  • not that I see.. I just looked at the spec again.. and the example they have for PasswordChange is Event PasswordChange(ByVal password_string As String).. they even have some code snipits.. but nothing showing them adding the handlers.. – kevin_kss Apr 23 '20 at 13:16
  • So if they use this delegate without sender argument, you _could_ grab yourself a stack trace and walk up the stack until you identified the sender, but that's _expensive_. See this question https://stackoverflow.com/questions/531695/how-to-print-the-current-stack-trace-in-net-without-any-exception. It's not a dupe, but the answers could be of interest. Just mind working with stack trace is _slloooowww_. – Fildor Apr 23 '20 at 13:19

0 Answers0