I tried to create and handle an event in C# for the first time but I met a problem.
I declared an event delegate in a static class called ArchiveurPerfsBJ.
Here the declaration :
public
I have implemented a callback method in the static class containing the main method. The class is called EntreeConsole.
Here is the prototype of the callback method :
private
I have written a statement to affect the callback method to the delegate as I read in a C# book. Unfortunately, the statement generates an error before execution. Here is the statement :
ArchiveurPerfsBJ
The error description informs me that ArchiveurPerfsBJ.VNoteArchive (i.e. The event delegate) is unreachable because of its protection level.
I don't know how to solve this problem so I have posted this message to get some help.
.VNoteArchive += ArchiveurPerfsBJ_VNoteArchive;static void ArchiveurPerfsBJ_VNoteArchive(object emetteur, VNoteArchiveEventArgs arguments) {...}static event EventHandler<VNoteArchiveEventArgs> VNoteArchive;
David RougierPosted Apr 11, 2011, 4:45 PM
I did not precise any modifier to the class VNoteArchiveEventArgs and the class is located in a project different from the one containing the class EntreeConsole. I have given the public modifier to the class VNoteArchiveEventArgs and the problem is now resolved.
Thanks for helping.
VulpesPosted Apr 11, 2011, 6:48 AM
I've even tried to model the situation myself with the console app below but it compiles and works fine:
Incidentally, where are you declaring the VNoteArchiveEventArgs class?
David RougierPosted Apr 10, 2011, 5:41 PM
I have reformated them as follows :
Here is the declaration of the event delegate in the static class ArchiveurPerfsBJ :
public static event EventHandler
Here is the prototype of the callback method in the static class containing the main method :
private static void ArchiveurPerfsBJ_VNoteArchive(object emetteur, VNoteArchiveEventArgs arguments)
{...}
Here is the statement to affect the callback method to the event delegate.
ArchiveurPerfBJ.VNoteArchive += ArchiveurPerfsBJ_VNoteArchive;
This statement generates a before-execution error. I have written this statement in the main method.
In response to Vulpes, the event delegate VNoteArchive has been declared public and the static class ArchiveurPerfsBJ as well.
VulpesPosted Apr 10, 2011, 11:26 AM