I've added a 2nd site collection with its own content db. My custom timer job now runs twice, I want it to run only once as it sends an email out.
How can I achieve this ?
Here is my code :
I've commented a few lines - contentDb.Sites[0].... (and I cant remember why) Could this be the answer ?
Also in previous post there was mention of 'If (mySiteCollection.ContentDatabase.Id.Equals(contentDbId))' but couldnt successfully target mySiteCollection ?
namespace DT_CustomTimerDriveAlert
{
class DriveAlert : SPJobDefinition
{
public DriveAlert()
: base()
{
}
public DriveAlert(string jobName, SPService service, SPServer server, SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
}
public DriveAlert(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
{
this.Title = jobName;
}
public override void Execute(Guid contentDbId)
{
// get a reference to the current site collection's content database
SPWebApplication webApplication = this.Parent as SPWebApplication;
//SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
// get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database
// -- SPList Listjob = contentDb.Sites[0].RootWeb.Lists["DT_TimerJob"];
SPSite site = webApplication.Sites["http://sp20104/sites/apps"];
SPWeb web = site.OpenWeb("mysite");
SPList Listjob = web.Lists["mylist"];