tags:

views:

406

answers:

3

I have a thread running in my program When Mouse-down Event generates I want to put that thread in wait() and in Mouse-up I want to Notify that thread

But when I tried to do this It is giving me error like "Object not locked by Thread" so can anyone help me how to solve this..

A: 

as far as i know, calling wait() on a thread causes a crash... i dont know if there is a safe way to pause a thread (or at least an easy way)

mtmurdock
A: 

You can't stop the UI Thread (this is the Thread that called the event). This Thread is used to dispatch UI events and if you could make it wait() it'll render your UI unresponsive.

You'll have to create your own Thread.

xamar
A: 

Just use Thread.sleep() and then Thread.interrupt() to wake it up.

something like this:

Thread t;

startThread() {
  t = new Thread() {
    public void run () {
       doThings();
       sleep(10000);
    }
  }

  t.start();
}

interruptThread() {
  if (t != null) t.interrupt();
}
Brad Hein