How do i add an entry in a listbox in a window that is in another thread. My Problem is, that i have to threads. One working thread, that does all the actual work and one thread for a window where i want to display status information. I tried to pass the form window as paramater in the constructor, but when i call it i get an exception.
Here is some of my code to illustrate the problem:
public partial class Mainform : Form
{
private string db = String.Empty;
private string password = String.Empty;
private string sqlinifile = String.Empty;
DatabaseListener dbListener;
StatusWindow statusWindow;
public Mainform()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
db = "EWAG";
password = "secret";
sqlinifile = "C:\\Programme\\Unify\\Team Developer 5.2\\sql.ini";
textBoxDB.Text = db;
textBoxPwd.Text = password;
textBoxSqlIni.Text = sqlinifile;
statusWindow = new StatusWindow();
dbListener = new DatabaseListener(statusWindow);
}
public void threadStarter()
{
this.dbListener.startSynchronizing(5);
}
void Button1Click(object sender, EventArgs e)
{
this.db = textBoxDB.Text;
this.password = textBoxPwd.Text;
this.sqlinifile = textBoxSqlIni.Text;
if (dbListener.connectToDatabase(db,"sysadm", password, sqlinifile))
{
this.Hide();
statusWindow.Show();
Thread synchronizer = new Thread(new ThreadStart(threadStarter));
synchronizer.Start();
}
}
}