您可以运行“服务"吗?从ASP.Net项目运行预定任务的程序? [英] Can you run a "service" that runs a scheduled task from an ASP.Net project?

查看:65
本文介绍了您可以运行“服务"吗?从ASP.Net项目运行预定任务的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我们的客户构建了Windows服务,该服务从数据库中收集所有已更改/新的行,将它们转换为CSV,FTP每晚将其上传到某个地方.现在事实证明,他们无权安装或运行Windows Service(这是仅Web路径托管的解决方案).

I built a Windows Service for a client of ours that collects all the changed/new rows from the database, turns them into a CSV and FTP uploads them somewhere every night. Now as it turns out they don't have access to install or run a Windows Service (it's a web path only hosted solution).

我认为修改Windows Service代码使其在ASP.Net进程中运行并从Global.asax实例化就足够容易了(我过去已经这样做过,在MVC项目中托管WCF服务) ).我们在使用Web表单的ASP.Net 4.0上,此任务每天晚上午夜(或其他配置的时间)运行Quartz和OpenPG.

I thought it would be easy enough to modify the Windows Service code to run inside the ASP.Net process and instantiated from the Global.asax (I've done this in the past, hosting a WCF service from within a MVC project). We're on ASP.Net 4.0, using web forms, and this task runs Quartz and OpenPG every night at midnight (or another configured time).

我的老板担心长时间没有人访问该站点时,托管过程处于休眠或卸载状态.我很确定这不会发生,但我不确定.

My boss was concerned about the hosting process sleeping or unloading during prolonged periods of no one hitting the site. I'm pretty sure this doesn't happen but I don't know with absolute certainty.

这项工作会按我认为的那样进行吗,或者以这种方式实施会不会有一些问题?

Will this work as I'm thinking it will, or will there be some issue to implementing it this way?

谢谢!

我知道您可以"(创建一个对象并调用一个不会阻止执行Application_Start的方法,该方法会触发计时器或后台线程或其他东西并在后台运行代码),但这是一个好主意并且ASP.Net托管进程会休眠/杀死正在运行的线程吗?如果是这样,我是否可以产生一个新线程(创建我自己的线程,或从池中使用一个线程)并使它无限运行而不会被杀死?

I know you "can" (create an object and call a method that doesn't block the execution of Application_Start that fires a timer or background thread or something and runs code in the background) but is it a good idea and will the ASP.Net hosting process sleep/kill the thread it's running on? If so, can I spawn a new thread (either create my own thread, or consume one from the pool) and have it run infinitely without being killed?

推荐答案

使用Window的Task Scheduler....这是其用途的完美示例.您可以让它直接调用程序集,也可以只用它来调用网站中的WCF端点.

Use Window's Task Scheduler....this is a perfect example of what it's for. You can have it call your assembly directly or you can just use it to call a WCF endpoint in your website.

这篇关于您可以运行“服务"吗?从ASP.Net项目运行预定任务的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆