Comment augmenter la croix fil des événements

Comment puis-je augmenter l'événement GeocodeAddressEventHandler partir d'un autre thread?

    System.Threading.Thread MapThread;
    WinformMap map ;

    public delegate void GeocodeAddressEventHandler(object sender, EventArgs e);
    public event GeocodeAddressEventHandler GeocodeAddressEvent;

    //How to Raise this Event from another thread??
    public void GeocodeAddress_Raised(object sender, EventArgs e)
    {
        MapLib.GeocodeAddress("12798 1ST ST", "", "", "");
    }

    public bool LoadMap(string restorepoint)
    {
        ////////////////////////Engine Controls////////////////////////////////////////////////////////
        try
        {
            System.ServiceModel.OperationContext context = System.ServiceModel.OperationContext.Current;

            //This is to instantiate a winform from a Console (will convert to service shortly) 
            MapThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
            {
                using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(context))
                {
this.GeocodeAddressEvent += new GeocodeAddressEventHandler(GeocodeAddress_Raised);
                 }
            }));
            MapThread.SetApartmentState(System.Threading.ApartmentState.STA);
            MapThread.Start();
            MapThread.Join();
        }
        catch (Exception ex)
        {
            return false;
        }

        return true; 
    }

En fait il s'est avéré que le thread a été appelé à disparaître après le champ d'application de la délégué résilié. Ce pourrait être un idiot de le faire, mais j'ai mis un certain temps d'Attente.vide { sommeil } que dans le champ d'application il n'a jamais mis fin, puis j'ai lancé le LoadMap à partir d'un autre thread, afin qu'il la confiture de mon service WCF en attente pour l'interminable file d'attente à la fin.

OriginalL'auteur bluepoisondartfrog | 2011-12-08