简体   繁体   中英

Singleton Serviced Component

I am trying to implement a serviced component as a singleton. Currently, my code is like this:

[assembly: ApplicationName("SingletonServicedComponent")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false)]

[ComVisible(true)]
[JustInTimeActivation(true)]
[ComponentAccessControl(false)]
[ProgId("Singleton.ServicedComponent")]
[ObjectPooling(Enabled = true, MaxPoolSize = 1, MinPoolSize = 1, CreationTimeout = 5000)]
public sealed class SingletonServicedComponent : System.EnterpriseServices.ServicedComponent
{
    private int value = 0;

    protected override bool CanBePooled()
    {
        return true;
    }

    public int Increment()
    {
        return this.value++;
    }
}

I am following the pattern of having it pooled, with a minimum and maximum instance count of 1. I signed my assembly and registered it with regasm and regsvcs. It shows up in Component Services console, and appears to be OK. However, when I instantiate it in different applications, I don't seem to be getting the same instance. Any thoughts?

Got it! I was getting an activation exception because I was not releasing (.Dispose(), = null) the instance I had, so other processes could not acquire a reference to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM