in

Finalizar componentes em .NET 3.5 no COM+.

Last post 08-08-2008 11:16 by lmagnani. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 08-08-2008 11:16

    Finalizar componentes em .NET 3.5 no COM+.

    Pessoal,

    Tenho um componente no COM+ implementado em .NET 3.5, o componente quando acessado por "client" em .NET 2.0, 3.0 e 3.5 os componentes são acessados e liberados corretamente, porém quando acesso com um "client" em .NET 1.1 os componentes são executados mas não finalizam (Objects e Activation são incrementados a cada chamada), "travando os componentes" após muitas execuções. Alguém sabe como solucionar esse problemas? Abaixo o código que estou utilizando:

    Componente:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.EnterpriseServices;
    using System.Runtime.InteropServices;

    namespace CompTestNet
    {

    public interface IMyInterface
    {
    string test();

    }

     

    [
    MustRunInClientContext(false)]

    [EventTrackingEnabled(true)]

    [JustInTimeActivation(true)]

    [Guid("7858F108-07D3-4f0e-8115-76928EEB7B08")]

    [ComponentAccessControl(false)]

    public class CompTestNet : ServicedComponent, IMyInterface

    {

    public string test()

    {

    string retorno = "";

    try

    {

    System.Diagnostics.EventLog.WriteEntry("Teste", "Execu‡ão de Componentes .NET 3.5");

    ContextUtil.DeactivateOnReturn = true;

    retorno = "OK";

    }

    catch (Exception ex)

    {

    System.Diagnostics.EventLog.WriteEntry("Teste", ex.Message);retorno = "NOK";

    }

    return retorno;

    }

    }

    }

     

    Client (button):

    private void button1_Click(object sender, System.EventArgs e)

    {

    object oActivator; object retorno;

    Type oTipo;

    oTipo = Type.GetTypeFromProgID("CompTestNet.CompTestNet");

    oActivator = Activator.CreateInstance(oTipo);

     

    retorno = oTipo.InvokeMember("test",BindingFlags.Default | BindingFlags.InvokeMethod,null,oActivator,null);

    MessageBox.Show(retorno.ToString());

    if (oActivator != null)

    {

    if (oActivator is IDisposable)

    {

    // tentativas para finalizar o objeto

    GC.Collect();

    ((IDisposable)oActivator).Dispose();

    System.Runtime.InteropServices.Marshal.ReleaseComObject(oActivator);

    oActivator =
    null;

    GC.WaitForPendingFinalizers();

    GC.Collect();

    }

     

    }

    }

Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems