I have created a function in c# code which called ZipFolders. In fact I am calling it from a Unity button and when it pressed try to zip folders inside a dir. Since in the same time I wanted to do something else I tried to call that function in a new thread. My question is how can I check if that thread is running or has stopped. My code
onGUI():
if (GUI.Button (new Rect (390, 250, 100, 50), "ZIP_FILES")) {
Thread thread = new Thread(new ThreadStart(zipFile));
thread.Start();
}
I want in an update function to check every time fi the thread is running or has stopped. How can I do so?
You can use thread.ThreadState
property
EDIT:
You can do like this;
public class YourClass
{
private Thread _thread;
private void YourMethod()
{
if (GUI.Button (new Rect (390, 250, 100, 50), "ZIP_FILES")) {
_thread = new Thread(new ThreadStart(zipFile));
_thread.Start();
}
}
private void YourAnotherMethod()
{
if (_thread.ThreadState.Equals(ThreadState.Running))
{
//Do ....
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With