D
dk60
Here is a problem I encountered concerning threads:
Here is the code in Form1 button click handler:
AddForm addForm = new AddForm(booksDataSet.Titles);
Thread addTitleThread=new Thread(new
ThreadStart(addForm.GetNewTitle));
addTitleThread.Start();
Here is the code in AddForm:
public AddForm(BooksDataSet.TitlesDataTable titlesTable)
{
InitializeComponent();
titles = titlesTable;
randomSleepTime = new Random();
}
private void AddButton_Click(object sender, EventArgs e)
{
lock(titles)
{
Thread.Sleep(randomSleepTime.Next(1, 3001));
titles.Rows.Add(Int32.Parse(ISBNTextBox.Text),
TitleTextBox.Text,
Int32.Parse(EditionTextBox.Text),
Int32.Parse(CopyrightTextBox.Text));
}
}
internal void GetNewTitle()
{
this.ShowDialog();
}
As long the second form (addForm) remains open, Form1 behaves just
fine, but after closing the second form, the dataGridView in Form1
misbehaves (no scroll bar, no refresh and so on)
What did I do wrong?
Thanks
Here is the code in Form1 button click handler:
AddForm addForm = new AddForm(booksDataSet.Titles);
Thread addTitleThread=new Thread(new
ThreadStart(addForm.GetNewTitle));
addTitleThread.Start();
Here is the code in AddForm:
public AddForm(BooksDataSet.TitlesDataTable titlesTable)
{
InitializeComponent();
titles = titlesTable;
randomSleepTime = new Random();
}
private void AddButton_Click(object sender, EventArgs e)
{
lock(titles)
{
Thread.Sleep(randomSleepTime.Next(1, 3001));
titles.Rows.Add(Int32.Parse(ISBNTextBox.Text),
TitleTextBox.Text,
Int32.Parse(EditionTextBox.Text),
Int32.Parse(CopyrightTextBox.Text));
}
}
internal void GetNewTitle()
{
this.ShowDialog();
}
As long the second form (addForm) remains open, Form1 behaves just
fine, but after closing the second form, the dataGridView in Form1
misbehaves (no scroll bar, no refresh and so on)
What did I do wrong?
Thanks