electron-egg electron-egg
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
❤️成为赞助商
  • 框架

    • 通信
    • http服务
    • socket服务
    • json数据库
    • sqlite数据库
    • 任务
      • 自动更新
      • 软件调用
      • Java服务
    • 操作系统

    • 特效

    • 硬件

    • 优惠券
    • 异常处理
    目录

    任务

    执行计算密集型业务或耗时业务时,你可以用job来处理。

    # 任务 / 并发任务

      // frontend/src/views/framework/jobs/Index.vue
      <script>
        runJob(jobId, operation) {
          let params = {
            id: jobId,
            type: 'timer',
            action: operation
          }
          this.$ipc.invoke(ipcApiRoute.someJob, params).then(data => {
            switch (data.jobId) {
              case 1:
                if (data.action == 'create') {
                  this.progress1_pid = data.result.pid;
                }
                break;
              case 2:
                if (data.action == 'create') {
                  this.progress2_pid = data.result.pid;
                }
                break;
            }
          })
        },
      </script> 
      
      // electron/controller/framework.js
      /**
       * 任务
       */ 
      someJob(args, event) {
        let jobId = args.id;
        let action = args.action;
        let result;
        switch (action) {
          case 'create':
            result = this.service.framework.doJob(jobId, action, event);
            break;       
          case 'close':
            this.service.framework.doJob(jobId, action, event);
            break;
          default:  
        }
        let data = {
          jobId,
          action,
          result
        }
        return data;
      }
      
      // Make sure to add code blocks to your code group

      # 任务池 / 并发任务

        // frontend/src/views/framework/jobs/Index.vue
        <script>
          createPool() {
            let params = {
              number: 3,
            }
            this.$ipc.send(ipcApiRoute.createPool, params);
          },
          runJobByPool(jobId, operation) {
            let params = {
              id: jobId,
              type: 'timer',
              action: operation
            }
            this.$ipc.invoke(ipcApiRoute.someJobByPool, params).then(data => {
              switch (data.jobId) {
                case 3:
                  if (data.action == 'run') {
                    this.progress3_pid = data.result.pid;
                  }
                  break;
                case 4:
                  if (data.action == 'run') {
                    this.progress4_pid = data.result.pid;
                  }
                  break;
              }
            })
          },
        </script> 
        
        // electron/controller/framework.js
        /**
         * 创建任务池
         */ 
        async createPool(args, event) {
          let num = args.number;
          this.service.framework.doCreatePool(num, event);
          return;
        }
        /**
         * 通过进程池执行任务
         */ 
        someJobByPool(args, event) {
          let jobId = args.id;
          let action = args.action;
          let result;
          switch (action) {
            case 'run':
              result = this.service.framework.doJobByPool(jobId, action, event);
              break;
            default:  
          }
          let data = {
            jobId,
            action,
            result
          }
          return data;
        }
        
        // Make sure to add code blocks to your code group

        # 完整代码

        • github前端代码 (opens new window)
        • github主进程代码 (opens new window)
        • gitee前端代码 (opens new window)
        • gitee主进程代码 (opens new window)
        上次更新: 2025/06/06, 07:21:49
        sqlite数据库
        自动更新

        ← sqlite数据库 自动更新→

        Theme by Vdoing | Copyright © 2023-2025 哆啦好梦 | 京ICP备15041380号-2
        • 跟随系统
        • 浅色模式
        • 深色模式
        • 阅读模式
        ×