delegate and event definition problem with compiler warnings

  • Thread starter Thread starter Peted
  • Start date Start date
P

Peted

Hi
Im using vs2008 c# 3.0 and am going through some other person(s) code
to clean up compiler warnings that are bieng produced.

I have this code (at bottom)


where a delegate/event is defined

and it builds ok with no errors but im trying to get rid of the
compiler warnings. The warning in this case is

Warning 35 The event
'TestCLassA.MainContainer.BillEventRedrawComplete' is never used


You can see from the code it is used but in a different class, not
seen at build time.

Im wondering if there is a way to make the warning go away, can i
intialise it, in some throw away fassion just to remove the warning.
If this was a simple car like an int thats what i would do.

I dont want to disbale warnings in the compiler, can anyone suggest
what i can do to remove this warning on build of this code

thanks for any help

Peted


namespace TestClassA
{

public delegate void BillEventRedrawComplete();

[Guid("A10D9EF1-508C-40b9-8B17-69E14CC08E3A")]
[ProgId("EMIS.PCS.BillingModule.MainContainer")]
[ClassInterface(ClassInterfaceType.None)]

public class MainContainer : System.Windows.Forms.UserControl
{


#region Custom Events

public static event BillEventRedrawComplete
BillEventRedrawComplete;
#endregion Custom Events

/... etc etc etc


then in another class,




namespace TestClassB
{


public class BillingEvent : UserControl, IBillingModule,
IBillingEvent
{

private void BillingEvent_Load(object sender, EventArgs e)
{
MainContainer.BillEventRedrawComplete += new
BillEventRedrawComplete(MainContainer_BillEventRedrawComplete);
}

etc etc etc
 
Im using vs2008 c# 3.0 and am going through some other person(s) code
to clean up compiler warnings that are bieng produced.

I have this code (at bottom)

where a delegate/event is defined

and it builds ok with no errors but im trying to get rid of the
compiler warnings. The warning in this case is

Warning 35 The event
'TestCLassA.MainContainer.BillEventRedrawComplete' is never used

That seems very odd. Could you produce a short but complete program
which shows it? Then we can report it to the compiler team.

Perhaps it's not "used" in terms of never being fired from within the
class - in which case I question its usefulness.

In terms of removing the warning, I'd use a pair of #pragma directives
around just that line of code - it makes it obvious what you're doing,
compared with using the event for no reason elsewhere.

As I say though, I can't see that it's currently doing anything useful
- just being able to subscribe to an event isn't really useful when it
never gets fired.

Jon
 
But nothing will ever *raise* that event; if you add some code that
invokes the event the message should disappear.

For info, you need to be careful with instances (such as BillingEvent)
subscribing to static events (such as BillEventRedrawComplete); it is
very easy for the event to keep all your instances alive by mistake.

Marc
 
Perhaps it's not "used" in terms of never being fired from within the
class - in which case I question its usefulness.

thats what im thinking
In terms of removing the warning, I'd use a pair of #pragma directives
around just that line of code - it makes it obvious what you're doing,
compared with using the event for no reason elsewhere.
i think i will try this

thanks

Peted
 
Back
Top