我正在使用Silverlight/WCF应用程序,当然在整个Silverlight程序中都有很多异步调用。我想知道如何处理创建客户端类和订阅的最佳方式。具体来说,如果我在一个方法中订阅一个事件,它返回后是否超出范围?C#异步调用垃圾回收
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?
}
}
如果我再次调用函数并创建另一个订阅,会遇到问题吗?
在此先感谢任何回复的人。
关于GC拧你,你没事按照http://stackoverflow.com/questions/421547/does-the-garbage-collector-destroy-temporarily-unreferenced-objects-during-async – Tanzelax 2010-03-24 18:05:51