How to init a background thread when app is loaded
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.
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
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.
Hi Zhong.
Please follow these steps:
Open your start page(see in app settings) in design mode.
Open events bottom panel.
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.
Thank you, Yurii.
and, how to avoid re-create the thread, can I query whether the thread is exist before create the thread?
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.