语言

Activity 类

定义

创建一个活动以执行同步或异步批处理工作,该工作可以使用 COM+ 服务,而无需创建 COM+ 组件。 此类不能被继承。

public ref class Activity sealed
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class Activity
[<System.Runtime.InteropServices.ComVisible(false)>]
type Activity = class
Public NotInheritable Class Activity
继承
Activity
属性

示例

下面的代码示例演示如何使用该 Activity 类并使用同步服务。

class SvcClass: IServiceCall
{
    static int callNumber = 0;
    public void OnCall()
    {
        callNumber++;
        System.Guid contextID = ContextUtil.ContextId;
        Console.WriteLine("This is call number "+ callNumber.ToString());
        Console.WriteLine(contextID.ToString());
        System.TimeSpan sleepTime = new System.TimeSpan(0,0,0,10);
        System.Threading.Thread.Sleep(sleepTime);
    }
}
class EnterpriseServicesActivityClass
{
    [STAThread]
static void Main(string[] args)
    {
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.Synchronization = SynchronizationOption.Required;
        serviceConfig.ThreadPool = ThreadPoolOption.MTA;
        SvcClass serviceCall = new SvcClass();
    Activity activity = new Activity(serviceConfig);
        activity.AsynchronousCall(serviceCall);
        activity.AsynchronousCall(serviceCall);
        Console.WriteLine("Waiting for asynchronous calls to terminate");
        Console.Read();
    }
}

注解

与活动关联的上下文完全由对象 ServiceConfig 确定。

构造函数

名称 说明
Activity(ServiceConfig)

初始化 Activity 类的新实例。

方法

名称 说明
AsynchronousCall(IServiceCall)

异步运行指定的用户定义的批处理工作。

BindToCurrentThread()

将用户定义的工作绑定到当前线程。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type。

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
SynchronousCall(IServiceCall)

同步运行指定的用户定义的批处理工作。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
UnbindFromThread()

取消绑定批处理工作,该批处理工作由SynchronousCall(IServiceCall)AsynchronousCall(IServiceCall)运行批处理工作的线程或方法提交。

适用于