Click here to Skip to main content
15,920,005 members
Home / Discussions / C#
   

C#

 
QuestionProblem receiving data through serial port Pin
naffilk18-Mar-07 2:46
naffilk18-Mar-07 2:46 
AnswerRe: Problem receiving data through serial port Pin
rbirkelbach19-Mar-07 5:03
rbirkelbach19-Mar-07 5:03 
Questionc# word xp textbox Pin
spinis18-Mar-07 0:00
spinis18-Mar-07 0:00 
AnswerRe: c# word xp textbox Pin
Thomas Stockwell19-Mar-07 8:26
professionalThomas Stockwell19-Mar-07 8:26 
QuestionBioinformatic algorithms in C# Pin
bufugus17-Mar-07 23:50
bufugus17-Mar-07 23:50 
AnswerRe: Bioinformatic algorithms in C# Pin
b0ksah19-Mar-07 0:28
b0ksah19-Mar-07 0:28 
QuestionGeneral info passer? Pin
gvanto17-Mar-07 22:39
gvanto17-Mar-07 22:39 
AnswerRe: General info passer? Pin
Stefan Troschuetz17-Mar-07 22:58
Stefan Troschuetz17-Mar-07 22:58 
The problem is that no event handlers are registered to the evtMainInfoShow event when you call ShowMainInfo in the DataFetcher class. Why? Simply because in the DataFetcher you're cteating a new instance of the InfoDisplay class that does not now you registered an event handler to the instance created in the main form. To overcome the problem of the exception being thrown when you call ShowMainInfo you have to check whether there are any event handlers registered to your event before calling it. Its common practise to encapsulate this in a protected OnEvent method:
class InfoDisplay
{
        public delegate void ehMainInfoShow(string s);
        public event ehMainInfoShow evtMainInfoShow;

        public InfoDisplay()
        {
            // do nothing
        }
        
        public void ShowMainInfo(string s)
        {
            evtMainInfoShow(s);
        }

        protected void OnMainInfoShow(string s)
        {
            if (evtMainInfoShow != null)
                evtMainInfoShow(s);
        }
}

Besides that change I suggest you also create a special EventArgs class that carries the string message and name this class and the delegate so they conform to the common naming pattern (eventHandler and eventArgs).
To overcome the problem of creating multiple instance of the InfoDisplay class, I'd suggest you let the class implement the singleton pattern so there exists only one instance that is accessible throughout your application. Let the main form register to the event of this instance and all other classes call ShowMainInfo.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

www.troschuetz.de

GeneralRe: General info passer? Pin
gvanto17-Mar-07 23:15
gvanto17-Mar-07 23:15 
GeneralRe: General info passer? Pin
Stefan Troschuetz17-Mar-07 23:39
Stefan Troschuetz17-Mar-07 23:39 
QuestionQuestion about office outlook Pin
ThetaClear17-Mar-07 21:56
ThetaClear17-Mar-07 21:56 
AnswerRe: Question about office outlook Pin
ThetaClear18-Mar-07 5:56
ThetaClear18-Mar-07 5:56 
QuestionHow to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly17-Mar-07 21:06
sherifffruitfly17-Mar-07 21:06 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Mudsoad17-Mar-07 21:47
Mudsoad17-Mar-07 21:47 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 6:42
sherifffruitfly18-Mar-07 6:42 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Stefan Troschuetz17-Mar-07 22:26
Stefan Troschuetz17-Mar-07 22:26 
AnswerRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 6:06
mveDave Kreskowiak18-Mar-07 6:06 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 6:48
sherifffruitfly18-Mar-07 6:48 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 9:07
mveDave Kreskowiak18-Mar-07 9:07 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 9:46
sherifffruitfly18-Mar-07 9:46 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
Dave Kreskowiak18-Mar-07 12:19
mveDave Kreskowiak18-Mar-07 12:19 
GeneralRe: How to get textbox (rich or plain) to remain scrolled to the bottom? Pin
sherifffruitfly18-Mar-07 12:45
sherifffruitfly18-Mar-07 12:45 
QuestionGetting pictures from camera Pin
Muammar©17-Mar-07 21:06
Muammar©17-Mar-07 21:06 
AnswerRe: Getting pictures from camera Pin
Christian Graus18-Mar-07 7:40
protectorChristian Graus18-Mar-07 7:40 
GeneralRe: Getting pictures from camera Pin
Muammar©18-Mar-07 23:59
Muammar©18-Mar-07 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.