调试 Sharepoint 计时器作业 [英] Debugging Sharepoint timer jobs

查看:73
本文介绍了调试 Sharepoint 计时器作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建我的第一个计时器作业并想要调试它.我已经通过一个功能安装了计时器作业,并将其添加到 Web 应用程序的 JobDefinitions 集合中,并添加了一个 SPMinuteSchedule 以每 5 分钟运行一次(用于测试目的).

I am creating my first Timer Job and want to debug it. I have installed the timer job through a feature, and added it to a webapplication's JobDefinitions collection, and added a SPMinuteSchedule to run every 5 minutes (for testing purposes).

然后,在 Visual Studio 中,我尝试将调试器附加到 WebApplication 的进程、中央管理进程和 OWSTIMER.exe 进程,但它不会调试到 TimerJob 的执行方法中.我在这里错过了什么.

Then, in Visual Studio I've tried attaching the debugger to the WebApplication's Process, the Central Admin process and the OWSTIMER.exe process, but it will not debug into the Execute Method of the TimerJob. What am I missing here.

附言计时器作业状态显示成功,因此它正在运行.奇怪...

P.S. The timer job status says succeeded, so it is running. Weird...

推荐答案

当我调试 TimerJobs 时,我在 Execute 方法的第一个开始处插入一个断言,这将始终失败.这会导致每次调用 Execute 方法时都会弹出一个窗口,因此您可以确保 TimerJob 已启动并且有足够的时间来附加调试器.当然,您必须在上线之前删除断言.

When I'm debugging TimerJobs I insert a Assertion at the very first begin of the Execute method, which will always fail. This results in a pop up every time the Execute method is called so you can be sure that the TimerJob was started and have enough time to attach the debugger. Of course you have to remove the Assertion before you go live.

System.Diagnostics.Trace.Assert(false);

更重要的事情是在部署新 DLL 后重新启动 Timer Service.否则,计时器服务将从旧 DLL 运行 TimerJob.

One more important thing is that you restart the Timer Service after you deployed a new DLL. Otherwise the Timer Service will run the TimerJob from the old DLL.

这篇关于调试 Sharepoint 计时器作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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