I'm a newbie at C#, and tho I try to dig in and fix my errors by myself, I finally found one i cant seem to solve by my self.
I'm developing a small program that interacts with an android Emulator, and i have put all the android VM details in a listbox, containing a few details that i need for my current app, such as VM ID.
All was working ok, until I put that part of the program working as a new task, instead of using the GUI task ( was locking the GUI ) But now this code is giving me headaches, as if i use If InvokeRequired on it, I lose access to the data, data that I actually need in the rest of the program.
Using it as it is throw an error of cross thread operation not valid. Any ideas on this one?
//Get VM Details from Listbox
for (int i = 0; i < AndroidList.Items.Count; i++) {
for (int j = 0; j < AndroidList.Items[i].SubItems.Count; j++) {
string Path = @"Includes/Settings/";
string jsonfile = File.ReadAllText(Path + AndroidList.Items[i].SubItems[j].Text + ".Json");
var fData = JsonConvert.DeserializeObject < AppSetupDetails > (jsonfile);
}
}
i need the values of i, j and fData to be passed along to be used in other parts of the code, just like the following
// Set VM resolution for the App
using (Process p = new Process())
{
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WorkingDirectory = memu.Text + @"/MEmu";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "/c memuc setconfig -i " + fData.MemuID.ToString() + " height 640";
p.StartInfo.FileName = "cmd.exe";
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();
}
i start the new task via button
public void AppStart_Click(object sender, EventArgs e)
{
Task task = new Task(new Action(AppFunctions));
task.Start();
}