利用aardio语言的fsys.dirWatcher监听目录文件变化的后台服务程序 不指定

jed , 2023-12-30 22:47 , 服务器技术 , 评论(0) , 阅读(137) , Via 本站原创 | |
示例一:


namespace service.threads;

//服务主线程
main = function(serviceName){
  import service;
  import thread.event;
  import fsys.log;
  import console;
  import sys.volume;
  import process;
  import fsys.dirWatcher;
  import fsys.dlg.dir;
  
  service.msgbox("服务已启动");
  console.open();
  //取所有分区信息
  var drives = sys.volume.getLogicalDrives()
  for(i,drv in drives){
    var info = sys.volume.getInfo( drv );
    if(info){
       var watchDir = info.drive;
       watcher = fsys.dirWatcher( watchDir )
       for( filename,action in watcher.eachChanges() ){
           fsys.log.print( watchDir + "\" + filename," -> ",action,'\r\n')
        console.log( watchDir + "\" + filename," -> ",action,'\r\n')
           }
      }
    
    }

}

//注意这也是一个独立的线程,用户控制服务停止或启动时都会触发此函数
control = function(control,eventType,pEventData){
    import service;
    import thread.event;
    
    var evtTask = thread.event("NT.SERVICE.CONTROL." + owner.serviceName,false);
    
    if( control == 0x1/*_SERVICE_CONTROL_STOP*/ ){  
        //控制线程中更新srvStatus,第一个参数只要指定需要更新的字段就行了
        service.updateStatus({currentState = 0x3/*_SERVICE_STOP_PENDING*/},owner.serviceName);
        evtTask.set();//使事件对象切换为有信号状态,使wait函数退出  
    }
    
    return 0x0/*_NOERROR*/
}



示例二:


namespace service.threads;

//服务主线程
main = function(serviceName){
  import service;
  import thread.event;
  import fsys.log;
  import console;
  import win.ui;
  import fsys.dirWatcher;
  import fsys.dlg.dir;
  
  //用win.form创建一个线程外包对象
  var winform = win.form();
  winform.messageOnly();//告诉他不需要显示窗口,只保留能处理消息的功能
  var watchDir = "C:";
  //创建监视线程
  winform.thrdWatcher = fsys.dirWatcher.thread(
    function(filename,action,actionText){
      fsys.log.print( watchDir + "\" + filename," -> ",action,'\r\n')
      console.log( watchDir + "\" + filename," -> ",action,'\r\n')
    }, watchDir);
  win.loopMessage();

}

//注意这也是一个独立的线程,用户控制服务停止或启动时都会触发此函数
control = function(control,eventType,pEventData){
    import service;
    import thread.event;
    
    var evtTask = thread.event("NT.SERVICE.CONTROL." + owner.serviceName,false);
    
    if( control == 0x1/*_SERVICE_CONTROL_STOP*/ ){  
        //控制线程中更新srvStatus,第一个参数只要指定需要更新的字段就行了
        service.updateStatus({currentState = 0x3/*_SERVICE_STOP_PENDING*/},owner.serviceName);
        evtTask.set();//使事件对象切换为有信号状态,使wait函数退出  
    }
    
    return 0x0/*_NOERROR*/
}

发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]