Confuse about Thread

G

Guest

Hi,all

I am confused about thread, Please help me,
I have two class, Calss One and Class Two,
Class One Has Class Two instance,Class Two has a Thread.

well, I want to quit Class One,Do I need to end Calss Two thread before I
end Class One instance?

If I should end Thread before I quit Class One,
How to wait for the thread end?

here is the source:

class one
{
private Two two;
public one()
{
two = new Two();
}

public void quit()
{
this.two.ThreadQuit = true;
//here wait for two thread end????
....
....
}
}

calss Two
{
private bool bQuit = false;
public Two()
{
Thread = new Thread(new ThreadStart(Threadproc))
}
private void Threadproc
{
while(true)
{
if(bQuit)
break;
DoSomthing();
}
}
public bool ThreadQuit
{
set
{
this.bQuit = value
}
}
}

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top