Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
GeneralRe: Compare Types Question Pin
Pete O'Hanlon9-Oct-12 7:27
mvePete O'Hanlon9-Oct-12 7:27 
GeneralRe: Compare Types Question Pin
Kevin Marois9-Oct-12 7:31
professionalKevin Marois9-Oct-12 7:31 
GeneralRe: Compare Types Question Pin
Pete O'Hanlon9-Oct-12 7:55
mvePete O'Hanlon9-Oct-12 7:55 
GeneralRe: Compare Types Question Pin
dojohansen10-Oct-12 3:12
dojohansen10-Oct-12 3:12 
GeneralRe: Compare Types Question Pin
BobJanova10-Oct-12 0:35
BobJanova10-Oct-12 0:35 
QuestionRe: Compare Types Question Pin
DaveyM6910-Oct-12 1:06
professionalDaveyM6910-Oct-12 1:06 
AnswerRe: Compare Types Question Pin
BobJanova10-Oct-12 1:45
BobJanova10-Oct-12 1:45 
QuestionWeka To C# Problems Pin
kimo_4u9-Oct-12 5:24
kimo_4u9-Oct-12 5:24 
SuggestionRe: Weka To C# Problems Pin
Richard MacCutchan9-Oct-12 5:31
mveRichard MacCutchan9-Oct-12 5:31 
GeneralRe: Weka To C# Problems Pin
kimo_4u9-Oct-12 5:33
kimo_4u9-Oct-12 5:33 
GeneralRe: Weka To C# Problems Pin
Pete O'Hanlon9-Oct-12 5:36
mvePete O'Hanlon9-Oct-12 5:36 
GeneralRe: Weka To C# Problems Pin
kimo_4u9-Oct-12 5:39
kimo_4u9-Oct-12 5:39 
GeneralRe: Weka To C# Problems Pin
Pete O'Hanlon9-Oct-12 5:45
mvePete O'Hanlon9-Oct-12 5:45 
GeneralRe: Weka To C# Problems Pin
Paul Conrad10-Oct-12 7:36
professionalPaul Conrad10-Oct-12 7:36 
QuestionMessage Closed Pin
9-Oct-12 4:59
sayem_sam9-Oct-12 4:59 
AnswerRe: gfhfgh Pin
Pete O'Hanlon9-Oct-12 5:02
mvePete O'Hanlon9-Oct-12 5:02 
SuggestionRe: gfhfgh Pin
Eddy Vluggen9-Oct-12 5:14
professionalEddy Vluggen9-Oct-12 5:14 
AnswerRe: gfhfgh Pin
Wes Aday9-Oct-12 5:06
professionalWes Aday9-Oct-12 5:06 
AnswerRe: gfhfgh Pin
Dave Kreskowiak9-Oct-12 6:00
mveDave Kreskowiak9-Oct-12 6:00 
JokeRe: gfhfgh Pin
Paul Conrad10-Oct-12 7:41
professionalPaul Conrad10-Oct-12 7:41 
AnswerRe: gfhfgh Pin
Keith Barrow9-Oct-12 6:27
professionalKeith Barrow9-Oct-12 6:27 
GeneralRe: gfhfgh Pin
OriginalGriff9-Oct-12 21:08
mveOriginalGriff9-Oct-12 21:08 
QuestionHelp With Delegates Pin
WebMaster9-Oct-12 3:00
WebMaster9-Oct-12 3:00 
AnswerRe: Help With Delegates Pin
n.podbielski9-Oct-12 3:53
n.podbielski9-Oct-12 3:53 
AnswerRe: Help With Delegates Pin
BobJanova9-Oct-12 3:53
BobJanova9-Oct-12 3:53 
You're thinking of delegates and events backwards. If you want LocalSource to call delegates in listeners, then it should publish an event, and listeners should hook onto it, i.e.

class LocalSource {
 public event NewFrameDelegate NewFrame;
 
 // ...

 private void MoveToNewFrame(){
  Bitmap bitmap = SomeMethodToMakeFrameImage();
  NewFrameDelegate newFrame = NewFrame;
  if(newFrame != null) newFrame(bitmap);
 }
}

class ViewingWindow : UserControl { // or whatever
 void SomeMethod() {
  LocalSource source = new LocalSource(this);
  source.NewFrame += bitmap => {
   // whatever
  };
 }
}


Alternatively, if you want the method to be called from the source, then you shouldn't be using a delegate at all, but an interface:

interface INewFrameListener {
 void NewFrame(Bitmap bitmap);
}

class LocalSource {
 // ...

 private void MoveToNewFrame(){
  Bitmap bitmap = SomeMethodToMakeFrameImage();
  INewFrameListener newFrameListener = ViewingWindow as INewFrameListener;
  if(newFrameListener != null) newFrameListener.NewFrame(bitmap);
 }
}

class ViewingWindow : UserControl, INewFrameListener {
 void NewFrame(Bitmap bitmap) {
  // whatever
 }
}

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.