C# Async call garbage collection

Posted by Troy on Stack Overflow See other posts from Stack Overflow or by Troy
Published on 2010-03-24T17:48:33Z Indexed on 2010/03/24 17:53 UTC
Read the original article Hit count: 260

Filed under:
|
|
|
|

Hello. I am working on a Silverlight/WCF application and of course have numerous async calls throughout the Silverlight program. I was wondering on how is the best way to handle the creation of the client classes and subscribing. Specifically, if I subscribe to an event in a method, after it returns does it fall 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?
    }
}

Will I run into problems if I call the function again and create another subscription?

Thanks in advance to anyone who responds.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf