471,350 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

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.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_BillEventRed rawComplete);
}

etc etc etc


Jun 27 '08 #1
3 1636
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.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
Jun 27 '08 #2
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
Jun 27 '08 #3
>
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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by ALI-R | last post: by
4 posts views Thread by ^MisterJingo^ | last post: by
2 posts views Thread by zamir.khan | last post: by
7 posts views Thread by Ant | last post: by
11 posts views Thread by matsi.inc | last post: by
6 posts views Thread by damiensawyer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.