看板 Web_Design 關於我們 聯絡資訊
實作 thread,大概有這三種方法︰ 1. 分段做 function createBatchProcess() { var running, keys; function start() { if (running) { return; } running = true; ... ... keys = Object.keys(books); setTimeout(next); } function next() { if (!keys.length) { return stop(); } var key = keys.shift(); print(books[key]); BatchTextImport(books[key], Word_Application); setTimeout(next); } function stop() { Word_Application.Quit(); Word_Application = null; running = false; } return { start: start }; } $("ProcessGo").click(createBatchProcess().start); 2. 用 generator function* genProcess() { ... ... for (var key in books) { yield print(books[key]); BatchTextImport(books[key], Word_Application); } Word_Application.Quit(); Word_Application = null; } var process = genProcess(); $("ProcessGo").click(function do(){ if (!process.next().done) { setTimeout(do); } }); 3. 用 Web Worker: http://is.gd/b0mcrA -- (* ̄▽ ̄)/‧★*"`'*-.,_,.-*'`"*-.,_☆,.-*` http://i.imgur.com/oAd97.png -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.81.100 ※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1437392863.A.148.html
iwasawasin: 感謝E大幫忙,請問若是E大比較推薦哪一種? 07/21 13:36
iwasawasin: Generator我查了資料後發現,這方法好像很實用,正在 07/21 13:40
iwasawasin: 考慮從這邊下手,不過可能要花點時間理解! 07/21 13:40
iwasawasin: 另外,IE好像不支援Generator的方法,可是Chrome好像 07/21 13:57
iwasawasin: 也不支援ActiveX Q___Q 07/21 13:57
eight0: 可以的話用 Web Worker。其它兩者只是在 js 中模擬,只有 07/22 08:24
eight0: worker 是系統級的 multithread。不過既然你只是要做 07/22 08:24
eight0: batch,挑自己方便的就行了 07/22 08:24