C # Async call garbage collection

I am working on a Silverlight / WCF application and, of course, have many asynchronous calls in a Silverlight program. I was wondering how to best deal with creating client classes and subscribing. In particular, if I subscribe to an event in a method, after it returns, it falls out of scope?

internal MyClass 
{
    public void OnMyButtonClicked()
    {
        var wcfClient = new WcfClient();
        wcfClient.SomeMethodFinished += OnMethodCompleted;
        wcfClient.SomeMethodAsync();
    }

    private void OnMethodCompleted(object sender, EventArgs args)
    {
        //Do something with the result

        //After this method does the subscription to the event
        //fall out of scope for garbage collection?
    }
}

Am I having problems if I call the function again and create another subscription?

Thanks in advance to everyone who answers.

+3
source share
2 answers

, - WCF . , . WCF IDisposable, , using Dispose; Service Proxy Helper , , .

async, , . "" WCF IDisposable, - Close/Abort .

, , async, , ; , " ", .

WCF , , ad-hoc; .

, ; .

+3

. WcfClient, OnMethodCompleted .

+2

Source: https://habr.com/ru/post/1738375/


All Articles