delegate and event definition problem with compiler warnings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peted

    delegate and event definition problem with compiler warnings

    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.Mai nContainer.Bill EventRedrawComp lete' 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 BillEventRedraw Complete();

    [Guid("A10D9EF1-508C-40b9-8B17-69E14CC08E3A")]
    [ProgId("EMIS.PC S.BillingModule .MainContainer" )]
    [ClassInterface( ClassInterfaceT ype.None)]

    public class MainContainer : System.Windows. Forms.UserContr ol
    {


    #region Custom Events

    public static event BillEventRedraw Complete
    BillEventRedraw Complete;
    #endregion Custom Events

    /... etc etc etc


    then in another class,




    namespace TestClassB
    {


    public class BillingEvent : UserControl, IBillingModule,
    IBillingEvent
    {

    private void BillingEvent_Lo ad(object sender, EventArgs e)
    {
    MainContainer.B illEventRedrawC omplete += new
    BillEventRedraw Complete(MainCo ntainer_BillEve ntRedrawComplet e);
    }

    etc etc etc




  • Jon Skeet [C# MVP]

    #2
    Re: delegate and event definition problem with compiler warnings

    On Jun 17, 10:48 am, Peted wrote:
    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.Mai nContainer.Bill EventRedrawComp lete' 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

    Comment

    • Marc Gravell

      #3
      Re: delegate and event definition problem with compiler warnings

      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 BillEventRedraw Complete); it is
      very easy for the event to keep all your instances alive by mistake.

      Marc

      Comment

      • Peted

        #4
        Re: delegate and event definition problem with compiler warnings

        >
        >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

        Comment

        Working...