ios - Stopping main thread execution -


My question is simple:

I want to stop the main thread running execution after a set timer Can it be done?

For example:

Mythread is running:

  while (true) {i ++; }  

I want to close after 10 seconds, so it will continue on the next command.

Notice, the main thread is actually working continuous CPU, its not sleeping ...


More specific, my problem is:

< P> My main thread is running Javascript which can be buggy and can be run forever, this method should be called in the main thread.

I want to stop the main thread from executing this javascript after 10 seconds (and go to next command, or catch block), I think it is not finished after 10 seconds Javascript Code is buggy and I do not want to continue to walk.

[webView stringByEvaluatingJavaScriptFromString: & lt; Some Java scripts that can take forever & gt;];

This is a problem, I can not disrupt the main thread, I can send a message in the message queue because the main thread is busy in CPU work.

Can this be done?


Comments