Jump to content
  • Advertisement
Sign in to follow this  
Goguigo

Thread, the Nightmare

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

:( Well, i meep working here fixing my app. I got a nokia manual where it talks about some threads. I quote the fellowing text:
[source code=javax]
class TestThread extends Thread
{
boolean running=true;
public void run()
{
while (running)
{
try
{
doSomething();
synchronized (this)
{
wait(1000);
}
}
catch (InterruptedException e)
{
}
}
}
public void kill()
{
synchronized (this)
{
notify();
running = false;
}
}
}

public void destroyApp(boolean unconditional)
{
myThread.kill();
try
{
// wait for the thread to actually die before continuing
thread.join();
}
catch (InterruptedException e)
{
// InterruptedException is never thrown
}
}
[/source code]

Well, my main issue here, with this code is that, how can i display a canvas? Cya

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You need something more like this:


public class MyCanvas javax.microedition.lcdui.Canvas implements Runnable
{
public void keyPressed( int iKey )
{}

public void keyReleased( int iKey )
{}

public void paint( Graphics g )
{}

/**....insert the rest of canvas fcns .....**/

int m_iState = 0;

public void run()
{
while( m_iState != -1 )
{
// Do stuff in the thread here

try{
Thread.sleep( 40 );
}catch( Exception e ) {}
}
}



Does that answer your Q?

Share this post


Link to post
Share on other sites
The thing i need to do is to create an application and kill it as clean as possible, to use the commandlistener from the cellphone. The code i posted at the beginning, dies in a very clean way, but i don't know how to implement a canvas there. The code you showed me Anonimous Poster (:P) i understand it very well, and many time's i had used it. Know what i mean? I dont know how to exit in a clean way.

:(

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!