Events within a DLL doesn't fire

A

Atilla Gökcegün

Hi guys,

i've created a Client- and a Server-Forms-Class and a Users-Class-Library.
The Class-Library (publisher) fires the event wich is handled within the
Client-Class (subscriber).. but the Client-Class gets never notified...

I've noticed that the following code:
if (UserInitialized != null)
{
UserInitialized(this, e);
}
returns null. that seems very strange to me because i've registered the
eventhandler within the Client-Class.
Is there a different workaround for implementing events within a
Class-Library...?

Dev. Environment:
VS2005 SP1, Framework 2.0, C#

Any help will be greatly appreciated
aTTi
 
J

Jon Skeet [C# MVP]

Atilla Gökcegün said:
i've created a Client- and a Server-Forms-Class and a Users-Class-Library..
The Class-Library (publisher) fires the event wich is handled within the
Client-Class (subscriber).. but the Client-Class gets never notified...

I've noticed that the following code:
if (UserInitialized != null)
{
UserInitialized(this, e);
}
returns null. that seems very strange to me because i've registered the
eventhandler within the Client-Class.
Is there a different workaround for implementing events within a
Class-Library...?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

I suspect you haven't actually subscribed to the event that you think
you have.
 
A

Atilla Gökcegün

what do you mean I haven't actually subscribed to the event..?
here is the code:

users-class-library:
public Users(string _user, int _color)
{
this._userName = _user;
this._colorNumber = _color;
e = new UserInitializedEventArgs("User: " + _user + " registered
at " + DateTime.Now.ToString());
OnUserInitialized(e);
}

public static void OnUserInitialized(UserInitializedEventArgs e)
{
if (UserInitialized != null)
{
MessageBox.Show("OnUserInitialized(" + e.Message + ") fired
up..");
UserInitialized(this, e);
}
}

client-class:
public Form1()
{
InitializeComponent();
Application.ApplicationExit += new
EventHandler(OnApplicationExit);
Users.Users.UserInitialized += new
UserInitializedEventHandler(Users_UserInitialized);
}

void Users_UserInitialized(object sender, UserInitializedEventArgs
e)
{
_userObject = (Users.Users)sender;
_userCustomColor = _userObject.TextFont;
}

even I put the namespace (users) to the client-class I need to put it within
code to see the users-class-library.. can you explain me that behaviour?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top