Timer hauj FeatureActivated thiab Feature tau

Kuv twb tau ua hauj lwm nrog ib co cai uas ib tug neeg tso kuv rau ib txoj hauj lwm hauv timer no.  Nws tsis tau muab qhov tseeb feature ua kom txoj kuv thiaj sau, tau mas.  Kuv coj kom zoo dua Andrew Connell nto moo blog ncej nyob rau cov kawm.

Kuv siv kuv siv qhov muag saib lub Studio 2010 thiab muaj txiag ceev cia zoo zoo tsis muaj ib qho kev ua yuam kev "yuam kev tshwm sim txiag kauj ruam 'Add kua': Kwv siv tsis tau rau thaj ntawm ib yam twj paj nruas."

Kuv twb noj nws chaws cia ib yam nkaus thiab.  Kuv yog scoping tus feature Web site daim ntawv qib, li:

image

Yog li ntawd, cov khoom uas yuav muab xa mus rau lub receiver uas yog los ntawm daim ntawv thov li qhov web, tsis muaj qhov chaw sau.  Thaum kawg, txoj cai zoo li no:

pej xeem override qhuav qhawv FeatureActivated(SPFeatureReceiverProperties zog)
{

    // Tsis txhob ua cov nram no nrog lub web app scoped nta, nws ua rau nws poob siab Luag nyav
    // SPSite chaw = zog.Feature.Parent li SPSite;

    SPWebApplication wa = zog.Feature.Parent li SPWebApplication;

    Yog hais tias (WA == null) pov tshiab kos("webapp2 yog thov.");

    foreach (SPJobDefinition hauj lwm hauv wa.JobDefinitions)
    {

        ua tiag
        {
            Yog hais tias (txoj hauj lwm.Lub npe == List_JOB_NAME)

                txoj hauj lwm.Rho tawm();
        }
        ntes (Kos e)
        {
            pov tshiab kos("cim 2");
        } // txhom kos e
    }

    // nruab qhov hauj lwm

    WeatherForecastTimerJob weatherForecastTimerJob =
        tshiab WeatherForecastTimerJob(List_JOB_NAME, WA);

    SPMinuteSchedule teem caij = tshiab SPMinuteSchedule();
    teem.BeginSecond = 0;
    teem.EndSecond = 59;
    teem.Luv = 5;
    weatherForecastTimerJob.Schedule = raws sij hawm;
    weatherForecastTimerJob.Update();

}

Tus yuam sij take-away yog tias thaum tus feature scoped rau lub Web site app, tus SPFeatureReceiverProperties SharePoint mus rau koj lub receiver feature kis tus Web site app theem tsis.  Andrew tus qub blog nkag assumes scoped mus rau hauv qhov chaw sau ntawv.

</kawg>

Subscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

sau ntawv cia

Koj email chaw nyob yuav tsis muab luam tawm. Search cim *