【发布时间】:2010-03-24 17:48:33
【问题描述】:
我正在开发一个 Silverlight/WCF 应用程序,当然在整个 Silverlight 程序中有许多异步调用。我想知道如何处理创建客户端类和订阅的最佳方式。具体来说,如果我在方法中订阅了一个事件,它返回后是否超出范围?
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 和你一起搞砸了,你可以按照stackoverflow.com/questions/421547/…
标签: c# .net wcf asynchronous