I am wanting to progmatically create a new threads that programatically creates a browser tab and performs events within that browser tab. The problem is that I get a message saying I cannot perform UI affects on UI objects in the parent thread.
So I need to find a way to tell the new thread to use the UI objects of the primary thread. This should be easy to do right?
Here is the snippet of code so far that I'm working with:
//....to this point we have told the code to run selected items in a datagrid. Each will have it's own thread.
if (row.Cells[1].Value.ToString() == "True")
{
count_active++;
//begin multithreading
Thread this_thread = new Thread(() => f_play_campaign(row.Cells[0].Value.ToString(), row.Cells[2].Value.ToString()));
this_thread.Name = "thread_" + row.Cells[0].Value.ToString();
this_thread.IsBackGround = true;
this_thread.Start();
}
}
if (count_active == 0)
{
MessageBox.Show("No campaigns are selected!");
}
}
private void f_play_campaign(string project_id, string tab_name)
{
//MessageBox.Show(tab_name);
//add new tab
string browsername = f_create_new_tab(tab_name); //this is where the code breaks!
Control browser = f_get_control_by_name(browsername);
//MessageBox.Show(browser.ToString());
//... do more code
Is there an easy way to tell the thread to use the UI objects of the primary thread? I could not figure out how to use Invoke() when I'm trying to get a return value from my method f_create_new_tab(), and I'm so new at this that I've not figured out how to use a background worker in the same fashion as threads.
I'll continue reading other threads on this issue but hopefully someone knows a extremely easy an elegant solution that would satisfy a php programmer like me.