WebPart.RenderWorkItemTimeout 方法
请注意:此 API 现在已过时。
将 Web 部件中的 HTML 呈现时的工作项已超时。
命名空间: Microsoft.SharePoint.WebPartPages
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
<ObsoleteAttribute("Use Page.RegisterAsyncTask instead.")> _
Protected Overridable Sub RenderWorkItemTimeout ( _
writer As HtmlTextWriter _
)
用法
Dim writer As HtmlTextWriter
Me.RenderWorkItemTimeout(writer)
[ObsoleteAttribute("Use Page.RegisterAsyncTask instead.")]
protected virtual void RenderWorkItemTimeout(
HtmlTextWriter writer
)
参数
writer
类型:System.Web.UI.HtmlTextWriter定义要呈现的工作项超时时的输出HtmlTextWriter对象。
备注
如果 Web 部件不重写RenderWorkItemTimeout方法,则呈现默认系统错误消息。< WebPartWorkItem > 标记包含在 web.config 文件中的 < SharePoint > 标记中的超时属性的值由指定的超时设置。
示例
下面的代码示例演示如何重写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");
}
}
}