Home > Net >  DtEventHandler? The Invoke () what do you mean
DtEventHandler? The Invoke () what do you mean

Time:10-11

Code meaning: dtEventHandler? The Invoke ();

1. What is this grammar, which means what?
2. Why is the infinite loop


 using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Using System. Diagnostics;
Using System. The Threading;
Using System. The Reflection;

The namespace ConsoleApplication1
{
Public class Program
{
Public delegate void (dt);
Public static event dt dtEventHandler;

The static void Main (string [] args)
{
DtEventHandler +=()=& gt;
{
DtEventHandler? The Invoke ();
};
The new Program (). RuntimeArgumentHandlse ();
Console.ReadKey();
}

Public void RuntimeArgumentHandlse ()
{
DtEventHandler ();
}

Public static void Test ()
{
The Console. Write (" I am a test ");
}
}
}

CodePudding user response:

If the dtEventHandler entrust content is not empty (no delegate instance in the MultiCast delegate chain), the delegate,

In general, not to "listen to yourself", but a direct call to the call, function is usually commissioned as part of the "interface" statement used to trigger events to notify external customers, external customers at this time what to call the target method didn't know it, so only use entrust event patterns,

In your code, you Invoke event (trigger), and their listening to this event and to Invoke event, cycle, not the end of the logic,

CodePudding user response:

When you want to use the method of ABC "own" to respond to an operation, you should write the
 public void RuntimeArgumentHandlse () 
{
DtEventHandler? The Invoke ();
}

To call your own method directly, is actually a "listening itself trigger" childish things, are defined dtEventHandler should be to distinguish between different projects, and then organize different people in different time points to the need of the development and the use of different engineering, for example, you intend to use in the future your DLL module can realize RuntimeArgumentHandlse specific the behavior, will trigger
 public void RuntimeArgumentHandlse () 
{
ABC ();
}

CodePudding user response:

When you want to use the method of ABC "own" to respond to an operation, you should write the
 public void RuntimeArgumentHandlse () 
{
ABC ();
}

To call your own method directly, is actually a "listening itself trigger" childish things, are defined dtEventHandler should be to distinguish between different projects, and then organize different people in different time points to the need of the development and the use of different engineering, for example, you intend to use in the future your DLL module can realize RuntimeArgumentHandlse specific the behavior, will trigger
 
Public void RuntimeArgumentHandlse ()
{
DtEventHandler? The Invoke ();
}


Note that unless you write (unit) test cases, otherwise don't effort to monitor their own event,
  •  Tags:  
  • C#
  • Related