5

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?

1

1 Answer 1

3

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 .... } } } 
Sign up to request clarification or add additional context in comments.

2 Comments

How can I check the thread state in another block of code?From where should I call thread state in order to check it all the time?
Make the thread a class variable and you can call it anywhere you want.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.