Hello guys,
i was wondering if there is any way to get the instance of program, because Gadgeteer builds singleton apps and doesn’t give us the reference of the instance to work with therefore i can’t create a new instance hince Singleton so the only way i can get the isntance righ now is by Modifiying the Program.generated .cs file which is a no no since that can be and will be overriden when i make a change in the designer so my question is how can i get hold of the instance… and in case you are wondering why i need that is simply to be able to call non-static method from a static member.
current generated code :
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Program program = new Program();
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
to make it work i do this
//*******************Added this**********************************
private static Program program = null;
public static Program Instance
{
get
{
return program;
}
}
//***************************************************************
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
//*******************Updated this****************************
program = new Program();
//***********************************************************
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
and here is why i need it: in Program.cs i can do this
public static void DoSomeWork(string relay) //static method can be access from other classes
{
Instance.Trigger(relay); //call the non static method.
}
public void Trigger(string relay) //non-static method that can access Gadgeteer modules.
{
if (relay == "relay1") relays.Relay1 = true;
if (relay == "relay2") relays.Relay2 = true;
}
is there away to change how the code is generated and the extra required code? or is there another way to do this?
thanks.