简体   繁体   中英

Call method c# with object sender and EventArgs

How can I call the following method manual?

  private void NetworkResponseReceived(object sender, Network.ResponseReceivedEventArgs e)
  {
         ExecuteTask();
  }

with something like:

NetworkResponseReceived();

what needs to be inserted within the parentheses?

Obviously you can call it this way

NetworkResponseReceived(null, new ResponseReceivedEventArgs());

But it would be lie. Handler expects that response is received (from some object), which is not true. I think it's better to extract handler's logic into separate method. And call that method both from your code and from handler. Like this:

void NetworkResponseReceived(object sender, Network.ResponseReceivedEventArgs e)
{
    // this method can have some arguments, if needed
    DoSomethingBusinessRelated();
}

And simply call same method, from other place:

DoSomethingBusinessRelated();

这应该工作:

NetworkResponseReceived(null, new Network.ResponseReceivedEventArgs());

试试这样;

NetworkResponseReceived(null, new ResponseReceivedEventArgs());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM