Page 1 of 1

How to init a background thread when app is loaded

Posted: Thu Jun 19, 2014 2:16 am
by Zhong Liu

Hello,
I need load a background thread, to scan files to be uploaded to backend. could someone give me some advises on this, thank you.


How to init a background thread when app is loaded

Posted: Thu Jun 19, 2014 3:52 am
by Yurii Orishchuk

Hi Zhong.

Please follow these steps:

  1. Open your start page(see in app settings) in design mode.

  2. Open events bottom panel.

  3. Add "Page load" JS event for this page and populate it with following code: http://prntscr.com/3u9xb5/direct

    pre

    var onNewThread = function(){
    //Here you should place the logic code you need in the new thread.
    console.log("new thread in work");
    };

    window.setTimeout(onNewThread, 100);

    /pre

    Regards.


How to init a background thread when app is loaded

Posted: Thu Jun 19, 2014 3:58 am
by Zhong Liu

Thank you, Yurii.


How to init a background thread when app is loaded

Posted: Thu Jun 19, 2014 4:18 am
by Zhong Liu

and, how to avoid re-create the thread, can I query whether the thread is exist before create the thread?


How to init a background thread when app is loaded

Posted: Thu Jun 19, 2014 5:02 am
by Yurii Orishchuk

Zhong,

You can modify code with following:

pre

var onNewThread = function(){

Code: Select all

 //Start thread 
 self.startThreadWorking = true; 

 //Here you should place the logic code you need in the new thread. 
 console.log("new thread in work"); 

 //End thread. 
 self.startThreadWorking = false; 

};
if(!self.startThreadWorking)
window.setTimeout(onNewThread, 100);

/pre

Regards.