Partager via


WebPart.RenderWorkItemTimeout - Méthode

Remarque : cette API est désormais obsolète.

Affiche le code HTML dans un composant WebPart lorsqu'un élément de travail a expiré.

Espace de noms :  Microsoft.SharePoint.WebPartPages
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
<ObsoleteAttribute("Use Page.RegisterAsyncTask instead.")> _
Protected Overridable Sub RenderWorkItemTimeout ( _
    writer As HtmlTextWriter _
)
'Utilisation
Dim writer As HtmlTextWriter

Me.RenderWorkItemTimeout(writer)
[ObsoleteAttribute("Use Page.RegisterAsyncTask instead.")]
protected virtual void RenderWorkItemTimeout(
    HtmlTextWriter writer
)

Paramètres

  • writer
    Type : System.Web.UI.HtmlTextWriter

    Objet HtmlTextWriter qui définit la sortie à restituer lorsqu'un élément de travail arrive à expiration.

Remarques

Si un composant WebPart ne remplace pas la méthode RenderWorkItemTimeout , un message d'erreur système par défaut est affiché. Le paramètre de délai d'expiration est spécifié par la valeur de l'attribut de délai d'expiration de la balise < WebPartWorkItem > contenue dans la balise < SharePoint > dans le fichier web.config.

Exemples

L'exemple de code suivant montre comment remplacer la méthode RenderWorkItemTimeout .

Imports System
Imports System.Web.UI
Imports System.Threading
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebPartPages

Public Class WorkItemSample
    Inherits Microsoft.SharePoint.WebPartPages.WebPart
    Private log As String = ""
    Private mre As New ManualResetEvent(False)

    Public Sub New()
        AddHandler Me.PreRender, AddressOf CreateThread
    End Sub

    Private Sub CreateThread(o As Object, e As EventArgs)
        RegisterWorkItemCallback(AddressOf DoWork, Nothing)
    End Sub

    ' Sleep for 4 seconds to simulate doing work
    Private Sub DoWork(o As Object)
        Thread.Sleep(4000)
        log += "hello from the thread pool!<BR>"
        mre.Set()
    End Sub

    Protected Overrides Sub RenderWebPart(output As HtmlTextWriter)
        output.Write(log)
    End Sub

    Protected Overrides Sub RenderWorkItemTimeout(output As HtmlTextWriter)
        output.Write("Timed out")
    End Sub
End Class
using System;
using System.Web.UI;
using System.Threading;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

namespace ExampleWebParts
{
    public class WorkItemSample : Microsoft.SharePoint.WebPartPages.WebPart
    {
        string log="";
        ManualResetEvent mre = new ManualResetEvent(false);

        public WorkItemSample()
        {
            this.PreRender+=new EventHandler(CreateThread);
        }

         private void CreateThread(object o, EventArgs e)
        {
            RegisterWorkItemCallback(new WaitCallback(DoWork), null);
        }

        // Sleep for 4 seconds to simulate doing work
        private void DoWork(object o)
        {
            Thread.Sleep(4000);
            log+="hello from the thread pool!<BR>";
            mre.Set();
        }

        protected override void RenderWebPart(HtmlTextWriter output)
        {
            output.Write(log);
        }

        protected override void RenderWorkItemTimeout(HtmlTextWriter output)
        {
            output.Write ("Timed out");
        }
    }
}

Voir aussi

Référence

WebPart classe

WebPart - Membres

Microsoft.SharePoint.WebPartPages - Espace de noms