How to abort spawned threads?

I use a separate thread for reading sensor-data.
The problem is that Unity editor environment does not abort threads that were spawned, they keep on running after stopping the application.
A practical solution could be to change the thread’s processing loop from:

while (true)
{
  Thread.Sleep(100);
  this.pm3.LowResolutionUpdate();
  print("update");
}

to something like:

while (!quit)
{
  Thread.Sleep(100);
  this.pm3.LowResolutionUpdate();
  print("update");
}

And set the shared variable “quit” from the main Unity thread before stopping the application. This quite clumsy, I would prefer all threads to be aborted when i stop the application. Is there a way to do this?

You can use MonoBehaviour.OnApplicationQuit() to get a notification when your application is stopped. You could put some code into there to Kill all the threads you spawned.

Thanks Jonas for the quick response, it works nice!