G
GroZZleR
Hey all,
I'm threading newbie, I've never attempted it before. I've got a
button that when clicked starts up a thread to process some files.
This keeps my GUI responsive and gets the tasks done.
Here's an example of what I'm doing:
====================================
private void button1_Click(object sender, System.EventArgs e)
{
if(_searchThread != null && _searchThread.IsAlive)
_searchThread.Suspend();
_searchThread = new Thread(new ThreadStart(TestThread));
_searchThread.IsBackground = true;
_searchThread.Start();
}
private void TestThread()
{
lock(_filesList)
{
_filesList.Items.Clear();
for(int i = 0; i < 15; ++i)
{
_filesList.Items.Add(i.ToString());
}
}
}
====================================
_filesList is a ListView control.
Is that lock all that's required to assure thread safety? My thread
doesn't appear to stack, so I know it's being suspended and such
properly. I don't get any exceptions, but as a threading noob, I want
to make sure I'm doing this right.
Thanks a lot guys.
I'm threading newbie, I've never attempted it before. I've got a
button that when clicked starts up a thread to process some files.
This keeps my GUI responsive and gets the tasks done.
Here's an example of what I'm doing:
====================================
private void button1_Click(object sender, System.EventArgs e)
{
if(_searchThread != null && _searchThread.IsAlive)
_searchThread.Suspend();
_searchThread = new Thread(new ThreadStart(TestThread));
_searchThread.IsBackground = true;
_searchThread.Start();
}
private void TestThread()
{
lock(_filesList)
{
_filesList.Items.Clear();
for(int i = 0; i < 15; ++i)
{
_filesList.Items.Add(i.ToString());
}
}
}
====================================
_filesList is a ListView control.
Is that lock all that's required to assure thread safety? My thread
doesn't appear to stack, so I know it's being suspended and such
properly. I don't get any exceptions, but as a threading noob, I want
to make sure I'm doing this right.
Thanks a lot guys.