vs widows服务的开发
2015-06-24 15:45
169 查看
最近再做一个视频管理系统,发现用户提交时实时转换视频非常慢。于是有了通过建立一个单独的服务。通过服务定时查询数据库,是否有需要转换的视频来解决问题。现把过程记录下来,已供参考
1、新建widows 服务项目
![](http://images0.cnblogs.com/blog2015/251562/201506/241538007991536.jpg)
2、增加查询定时器在服务启动时
3、通过Timer的Elapsed事件处理定时任务
1、新建widows 服务项目
![](http://images0.cnblogs.com/blog2015/251562/201506/241538007991536.jpg)
2、增加查询定时器在服务启动时
protected override void OnStart(string[] args) { // 单位为毫秒 System.Timers.Timer timer = new System.Timers.Timer(1000); timer.AutoReset = true; timer.Enabled = true; timer.Elapsed += timer_Elapsed; timer.Start(); }
3、通过Timer的Elapsed事件处理定时任务
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { // 加载外置配置文件 //得到当前服务的安装路径 string basepath = AppDomain.CurrentDomain.BaseDirectory; XmlDocument xml = new XmlDocument(); xml.Load(basepath + "\\videoconvertconfig.xml"); XmlNode rootNode = xml.SelectSingleNode("root"); string sqlConn = rootNode.Attributes["sqlConn"].Value; //得到ffmpeg的路径 string ffmpegPath = rootNode.ChildNodes[0].Attributes["path"].Value; try { using (SqlConnection conn = new SqlConnection(sqlConn)) { conn.Open(); SqlDataAdapter data = new SqlDataAdapter("select videoaddress,id from viedoList where isconvert=0", conn); DataSet ds = new DataSet(); data.Fill(ds); DataTable VideoList = ds.Tables[0]; VideoConvert vc = new VideoConvert(); foreach (DataRow dr in VideoList.Rows) { // 视频转换 vc.convertVideo(basePath, ffmpegPath, dr[0].ToString()); // 转换成功 更新数据库 updateData(conn,dr[1].ToString()); } } } catch (Exception err) { Common.WriteFile(basePath+"/log/log.txt", err.Message); } }
相关文章推荐
- 【转】Tomcat版本是32位、64位问题
- IT架构之IT架构模型——思维导图
- New hooks for theme suggestions
- DICOM医学图像处理:DICOM存储操作之 “多幅JPG图像数据存入DCM文件”
- lnmp 环境搭建 源代码包安装 linux,nginx,mysql,php
- Activity之间数据传递与共享的几种途径(bitmap篇)
- swift 源码网站 code4app
- php获取路径
- Python 实现 淘宝秒杀 聚划算 自动提醒 源码
- INF文件的定义
- photoSwipe插件使用
- 垂直滚动条测试
- [php] UEditor富文本编辑器(thinkphp)
- String.format()【示例详解】
- [JQ权威指南]第七天:使用val()方法设置和获取元素的值
- SSH中各个框架的作用以及Spring AOP,IOC,DI详解
- String.format()【示例详解】
- [Javascript + rxjs] Introducing the Observable
- Oracle job调用存储过程
- joomla!读取数据库操作,使用JDatabase