4

I have a program with the following design

  • A couple of separate classes, each implementing one type of algorithm
  • A windows form interface for providing input to run different algorithms AND Speech Commands to do exactly the same.
  • Each algorithm is run by clicking a separate button
  • Each algorithm raises some events (specific to the algorithms)
  • The event listeners in turn outputs through
  • The labels on the form AND through the speech API, speaks the results using speakers

The problem I am facing is that while debugging, if something goes wrong in one algorithm, other algorithms get initiated automatically sometimes. I want to be able to know what event listeners are registered with some event if any, at any point in time. I am using VS2008 with C#.

I also want to know if we use a Timer as a local variable and add an event listener to that timer in each class. Is is possible that the timer of one class triggers the listeners in other classes. I am new to this event listeners stuff, and not sure if I am missing some basic information that led me asking this question or its a problem with some ground.

Novice
  • 515
  • 7
  • 22

1 Answers1

2

i would suggest you get basics of debugging, i think this is all that you need for now. Here is a tutorial to basics of debugging. Get yourself familiar with F10 and F11 keys. by using breakpoints you can get the execution sequence of your algorithms.

2nd it is possible to that the timer of one class triggers the listeners in other classes Here is an example.

MyClass myClass = new MyClass();
Timer timer1 = new Timer();
timer1.Tick += myClass.TimerCallback; // subscribe to other's class method
timer1.Interval = 1000;
timer1.Start();

public class MyClass
{
    public void TimerCallback(object sender, EventArgs eventArgs)
    {
        Console.WriteLine("Timer Called by: " + sender);
    }
}

if you want to get list of callbacks subscribe to your callback use this answer, but i think you dont need that for now if you get use to debugging.

Community
  • 1
  • 1
Mujahid Daud Khan
  • 1,983
  • 1
  • 14
  • 23
  • I am familiar with the F10 and F11 its just that I want to know what listeners are registered. Where do I get this information. Furthermore, if I have a timer and a callback function in every class, will the tick of one timer effect others. Lets say I have two objects of two different classes and each has its own timer set to different time interval. Is it possible that the timer tick for one class initiate the tick of the other also. – Novice May 09 '13 at 07:45