Home > Net >  Online, etc., on the question of agency.
Online, etc., on the question of agency.

Time:11-11

Declare a proxy approach, no parameters,
Public delegate void FileChangeDelegate ();


Place called
Private void RegisterFileWatch (FileReadRequest request, FileChangeDelegate onChanged)
{
FileWatch. Changed -=new FileSystemEventHandler (onChanged);//here
}
//new FileSystemEventHandler need such parameters method agent (object source, FileSystemEventArgs e)
//is there any way to further under the packaging, let the incoming onChanged don't need to define the parameters?

CodePudding user response:

You this writing is not only a trouble, and the object (logical) is incorrect,

First of all, the traditional method of a complete statement of registration, cancellation method:
 private void test (object sender, EventArgs e) 
{
Cs. MessageReceived -=Cs_MessageReceived;
}

[code=csharp] private void Cs_MessageReceived (object sender, MessageReceivedEventArgs r)
{
.
}
[/code] c # compiler realized here method is a static method,

And the delegate object generated by the dynamic, you will need to manually save your code, for example:
 Action The CSV. 

Private void test1 (object sender, EventArgs e)
{
CSV=new Action ((s, arg)=& gt;
{
.
});
Cs. MessageReceived +=CSV;
}

Private void test2 (object sender, EventArgs e)
{
If (CSV!=null)
Cs. MessageReceived -=CSV;
}


Here, you'll have to entrust the statement as object, and then use "accurate object instance" to register, log off,
  •  Tags:  
  • C#