James Mann's Blog

The blog of James Mann

Persisting state in Sharepoint timer job definitions

Using class member variables will not work if you want to persist state between invocations. This seems to be due to the way sharepoint manages timer jobs. A solution is to use the Properties *property* which is exposed to all SPJobDefinition subtypes. This is a hashtable which accepts a key value pair. Usage:

public class SampleTimerJob : SPJobDefinition
{
    public SampleTimerJob(string jobName, SPWebApplication webApplication, string url, string email)
        : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
    {
        ContainerSite = url;
        Email = email;

        this.Title = "sample timer";
    }

    public string ContainerSite
    {
        get { return Properties["site"].ToString(); }
        set { Properties["site"] = value; }
    }

    public string Email
    {
        get { return Properties["email"].ToString(); }
        set { Properties["email"] = value; }
    }

    public override void Execute(Guid targetInstanceId)
    {
        SPSite site = new SPSite(ContainerSite);

        using (SPWeb web = site.OpenWeb())
        {

            SPUtility.SendEmail(web, false, false, Email,
                                "title",
                                "content");
        }
    }
}
  • Buy Cialis Online

    2/23/2008 3:26:33 PM |

    Hi, nice post. I couldn't understand some parts of the article but it sounds interesting..
    Continue writing...

  • Natural Male Enhancement

    3/4/2008 1:24:52 PM |

    Hello, of course I came to visit your site and thanks for letting me know about it.
    I just read this post and wanted to say it is full of number one resources. Some I am familiar with. For those who don’t know these other sites they are in for a treat as there is a lot to learn there.

  • WhagetagMaype

    3/18/2008 11:19:59 AM |

    http://www.dating.love-chat.ru/ -
    это служба знакомств, где вы можете познакомиться и пообщаться с понравившимся человеком.  Все красивые девушки и парни у нас.

  • Arbiffphill

    3/19/2008 1:15:56 PM |

    Все для телефона - java-игры, картинки, темы оформления для телефонов, реалтоны, java-книги, видеоролики. Ежедневные обновления.

  • Arbiffphill

    3/19/2008 7:51:57 PM |

    Уникальная доска объявлений Рунета, на которой вы обязательно увидите нужную вам информацию и добавить свое объявление. Все объявления разнесены по рубрикам и подрубрикам. О вас узнает весь мир!

  • HenPaseenveby

    3/22/2008 10:35:34 AM |

    http://www.sochi-hotels.info/ - Сочи: каталог гостиниц Сочи.
    Отели в Сочи, частные гостиницы, комфортабельные пансионаты и санатории.

  • mymalifex

    3/28/2008 4:20:39 AM |

    Hi All,
    Can anybody help me with my wife? I think she unfaithfulness. my email is peter_griffin1971@mail.com

    WBR,
    Alex
    http://world-viagra.com
    My favourite pharma supermarket

  • mymalifexx

    3/30/2008 4:38:56 AM |

    Great,
    I think that my wife unfaithful to me. My e-mail is davidxleon1964@yahoo.co.uk.
    I have a wonderful plan for disclosure of her deceit.
    WBR,
    David
    http://world-viagra.com - my favourite pharma supermaket

  • mymalifexx

    3/30/2008 7:37:09 PM |

    Great,
    I think that my wife unfaithful to me. My e-mail is davidxleon1964@yahoo.co.uk.
    I have a wonderful plan for disclosure of her deceit.
    WBR,
    David
    http://world-viagra.com - my favourite pharma supermaket

  • mymalifexx

    3/30/2008 7:37:17 PM |

    Great,
    I think that my wife unfaithful to me. My e-mail is davidxleon1964@yahoo.co.uk.
    I have a wonderful plan for disclosure of her deceit.
    WBR,
    David
    http://world-viagra.com - my favourite pharma supermaket

  • Online Casino

    4/15/2008 2:25:55 AM |

    I will bookmark your article for future use. It was very interesting and informative. Thank you.
    Have a nice day and continue working in the same way! ;)

  • Blengeple

    9/8/2008 9:39:55 PM |

    hot penny stock picks
    penny stock picks
    Technical Analysis
    http://www.greencashmoney.com">stock market picks
    Smallcap Sleepers
    top 10 stocks to buy
    Investor Newsletter
    stock newsletters

  • Steve

    2/12/2009 9:51:07 PM |

    This does not seem to be true according to our experiments. We have gotten jobs to successfully serialize and deserialize member data. We had to tag each member variable that we wanted serialized with "[Persisted]". After that it worked fine.

  • Steve

    9/5/2009 11:39:06 AM |

    where does this properties get saved.

  • Steve

    9/5/2009 11:39:14 AM |

    where does this properties get saved?

Loading