calling a non static method from a static method in a dll class
-
namespace NecRoutines
{
public class Invoke
{
private System.Windows.Forms.Timer TrzTimer = new System.Windows.Forms.Timer();
private void TrzInitialize()
{
this.TrzTimer.Tick += new System.EventHandler(this.TrzTimer_Tick);
TrzTimer.Interval = 1000;
TrzTimer.Enabled = true;
TrzTimer.Start();
}
private void TrzTimer_Tick(object sender, EventArgs e)
{
// do something when time elapses
}public static void TrzStart() { TrzInitialize(); }
}
}//An object reference is required for the non-static field, method, or property
this is the error message that i get for calling TrzInitialize() during building this DLL program. Consider that TrzInitialize() must be non static because of timer routine definition and TrzStart() must be static to be known for main program. thanks
-
namespace NecRoutines
{
public class Invoke
{
private System.Windows.Forms.Timer TrzTimer = new System.Windows.Forms.Timer();
private void TrzInitialize()
{
this.TrzTimer.Tick += new System.EventHandler(this.TrzTimer_Tick);
TrzTimer.Interval = 1000;
TrzTimer.Enabled = true;
TrzTimer.Start();
}
private void TrzTimer_Tick(object sender, EventArgs e)
{
// do something when time elapses
}public static void TrzStart() { TrzInitialize(); }
}
}//An object reference is required for the non-static field, method, or property
this is the error message that i get for calling TrzInitialize() during building this DLL program. Consider that TrzInitialize() must be non static because of timer routine definition and TrzStart() must be static to be known for main program. thanks
You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like
public static void TrzStart(Invoke instance)
{
instace.TrzInitialize();
}No more Mister Nice Guy... >: |
-
You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like
public static void TrzStart(Invoke instance)
{
instace.TrzInitialize();
}No more Mister Nice Guy... >: |
-
You cannot call TrzInitialize from static method. Its common sense. Since Invoke.TrzStart is static and you have 10 instances if Invoke class which of them you want to use to call TrzInitialize? You have to explicilty set that instance like
public static void TrzStart(Invoke instance)
{
instace.TrzInitialize();
}No more Mister Nice Guy... >: |
-
Everybody was at some point. Don't worry about that. Glad that could help.
No more Mister Nice Guy... >: |