嘿,这是如何用VB.NET编写的?这是我在http://www.codeproject.com/KB/silverlight/SynchronousSilverlight.aspx上发现的一个示例.
ThreadPool.QueueUserWorkItem(delegate
{
var channelFactory = new ChannelFactory<ISimpleService>("*");
var simpleService = channelFactory.CreateChannel();
var asyncResult = simpleService.BeginGetGreeting("Daniel", null, null);
string greeting = null;
try
{
greeting = simpleService.EndGetGreeting(asyncResult);
}
catch (Exception ex)
{
displayMessage(string.Format(
"Unable to communicate with server. {0} {1}",
ex.Message, ex.StackTrace));
}
displayGreeting(greeting);
});
解决方法:
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf GetGreeting))
Private Sub GetGreeting(o As Object)
Dim channelFactory = New ChannelFactory(Of ISimpleService)("*")
Dim simpleService = channelFactory.CreateChannel()
Dim asyncResult = simpleService.BeginGetGreeting("Daniel", nothing, nothing)
Dim greeting As String = nothing
Begin Try
greeting = simpleService.EndGetGreeting(asyncResult)
Catch ex As Exception
displayMessage(String.Format("Unable to communicate with server. {0} {1}", ex.Message, ex.StackTrace))
End Try
displayGreeting(greeting)
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。