T
Tony Johansson
Hi!
Here is a simple example on a timer accessing the private method
timer_Elapsed. This works fine.
In this example one might consider that the timer_Elapsed must be public
because the one that is calling is not
within the class.
So I just wonder is it always in such a way that when the framework or the
OS is calling upon a method it can be declared as
private and it will work ?
class Test
{
static void Main()
{
Timer timer = new Timer();
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 1000;
timer.Enabled = true;
Console.ReadLine();
}
private static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("Working");
}
}
//Tony
Here is a simple example on a timer accessing the private method
timer_Elapsed. This works fine.
In this example one might consider that the timer_Elapsed must be public
because the one that is calling is not
within the class.
So I just wonder is it always in such a way that when the framework or the
OS is calling upon a method it can be declared as
private and it will work ?
class Test
{
static void Main()
{
Timer timer = new Timer();
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 1000;
timer.Enabled = true;
Console.ReadLine();
}
private static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("Working");
}
}
//Tony