0

I'm confused if i should use the using statement inside an event because the event is "asynchronous" and the object can be disposed before ending the job. Or am i missing something

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        //var web = (SPWeb)properties.Feature.Parent;
        using(var web = (SPWeb)properties.Feature.Parent)
        {
           if (web == null) return;

           DreamerRemindersTimerJob.InstallTimerJob(web.Site.WebApplication, true);
           DreamerMetaDataTimerJob.InstallTimerJob(web.Site.WebApplication, true);
           DreamerCleanUpTimerJob.InstallTimerJob(web.Site.WebApplication, true);          
       DreamerWorkFlowErrorsTimerJob.InstallTimerJob(web.Site.WebApplication, true);
        }

    }

1 Answer 1

4

No, you should not use a using as you're not instantiating the object - you're getting a reference to an existing object. Let the event receiver handle the life cycle of its own objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.