I'm trying to run a method on a separate thread, but when I try initializing the the new thread I get this error:
A field initializer cannot reference the non-static field, method, or property Form1.update()
The update method:
public void update()
{
XmlDocument doc = new XmlDocument();
status s = new status();
doc.LoadXml(s.getStatus("12345"));
char[] xmlChar = { 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
int[] lightStatus = new int[9];
int[] doorStatus = new int[5];
int[] fanStatus = new int[5];
int[] windowStatus = new int[5];
for (int i = 1; i < 9; i++)
{
XmlNode lights = doc.SelectSingleNode("All/Lights/status/" + xmlChar[i] + "/text()");
lightStatus[i] = Convert.ToInt16(lights.Value);
}
for (int i = 1; i < 5; i++)
{
XmlNode fans = doc.SelectSingleNode("All/Fans/status/" + xmlChar[i] + "/text()");
XmlNode doors = doc.SelectSingleNode("All/Doors/status/" + xmlChar[i] + "/text()");
XmlNode windows = doc.SelectSingleNode("All/Windows/status/" + xmlChar[i] + "/text()");
fanStatus[i] = Convert.ToInt16(fans.Value);
doorStatus[i] = Convert.ToInt16(doors.Value);
windowStatus[i] = Convert.ToInt16(windows.Value);
}
u1.update(lightStatus);
u2.update(fanStatus);
}
I am getting an error on the initializer:
System.Threading.Thread updateThread = new System.Threading.Thread(update);