473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Delegate is Null

I am experiencing a problem using an event to log to a file. The problem is
that in the second wiring, the following is always null - never the case in
the first wiring

protected void OnLog(string message)
{
if(Log!=null) Log(message);
}

In my static main I have two delegate wires to the same event

qbthread.Log +=new Namespace.....QBThread.LogHandler(log.Add);
dba.Log +=new Namespace....Console.DB.DatabaseFactory.LogHandler (log.Add);

In the qbathread the reference is not null and is working, but in the dba
the reference is always null.

Both the qbathread and the dba thread have this code in their class:
#region Wire to the Logger Section

# region Delegates
public delegate void LogHandler(string message);
#endregion

#region Events
public event LogHandler Log;
#endregion

# region Protected Methods
protected void OnLog(string message)
{
if(Log!=null) Log(message);
}
#endregion

#endregion

And the log.add call is a reference to a function that writes to a log file.

Any help is appreciated, I can send more code if this doesnt make any sense!
Thanks

Nov 16 '05 #1
2 2593

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.740 / Virus Database: 494 - Release Date: 16/08/2004
Nov 16 '05 #2
Chris Fink <Ch*******@discussions.microsoft.com> wrote:
I am experiencing a problem using an event to log to a file. The problem is
that in the second wiring, the following is always null - never the case in
the first wiring


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
8
by: Paul | last post by:
Hi, I have the following code in a winform: .... private delegate void DownloadDelegate(string src, string dest); .... private void DownloadFile(string src, string dest) { WebClient wc =...
3
by: N8 | last post by:
I am trying to get an exception to occur and consequently found that when adding a target method to a delegates invocation list, a copy of that object is added instead of a reference to the object....
5
by: Doug Handler | last post by:
Hi, I have a form (Form1) that contains a tab control which one tab has a customer user control (UserControl1). When the user double-clicks on the grid hosted there a new user control is...
2
by: shengmin.ruan | last post by:
when i use delegate like this: ----------------- protected override void WndProc(ref Message m) { delegate_ReplyFromDataProcess = new...
8
by: Jeff S. | last post by:
I was recently advised: << Use List<struct> and Find() using different Predicate delegates for your different search needs.>> What is "Predicate delegate" as used in the above recommendation? ...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
7
by: colin | last post by:
Hi, How can I use a delegate that I can set to call a non static function but of any instance of the class ? eg class TypeTeader<T> { delegate T readDelegate<T>();
7
by: Eric | last post by:
I have a number of static helper methods to read in data from an IDataReader; one of the services provided by this helper class is the ability to return a nullable type as needed, for instance:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.