I have two classes in the same namespace, Form1 and NewAccount. I am attempting to call an instance method that will reload a combobox on Form1. I have Form1 implemented as a singleton, and a static method in Form1, but I cannot access the instance method 'LoadAccounts() ' which will reload the combobox.
My understanding of the singleton pattern was that the call
would check for an existing instance, and if one is not present, the class would be instantiated.
If this means that Form1 will always exist when this is called, I thought I would then be able to call any instance method of that class, which does not seem to be the case. Can I simply not call instance methods from a static method?
Code:
public static void SetAccountID(string account)
{
Form1._instance.Show(); //checks for an open instance
Form1.LoadAccounts(); //not sure how to/if I can call instance function
}
My understanding of the singleton pattern was that the call
Code:
Form1._instance.Show();
Code:
public Form1 Instance
{
get
{
if (Form1._instance == null)
{
Form1._instance = new Form1();
}
return Form1._instance;
}
}
private static Form1 _instance = null;
Comment