另一种方法是使用Rx(Reactive Extensions)框架来封装具有一些非常有趣的特性的自动完成。
通过Rx,您可以组合(多个事件源),限制用户输入,以便不会压倒源,并且最重要的是,如果用户在搜索框中键入更多内容,则可以忽略旧结果(TakeUntil)。
更多信息:
Rx: Curing your asynchronous programming blues
Curing the asynchronous blues with the Reactive Extensions for .NET
例子:
SO: RX AutoCompleteBox
RxProperty = Observable.FromEvent<TextChangedEventHandler, TextChangedEventArgs>(
h => new TextChangedEventHandler(h),
h => AssociatedObject.TextChanged += h,
h => AssociatedObject.TextChanged -= h)
.Select(t => ((TextBox)t.Sender).Text)
.Throttle(TimeSpan.FromMilliseconds(400))
.SubscribeOnDispatcher()
.Take(10)
.TakeUntil(AssociatedObject.TextChanged);
相反FromEvent,你可以用FromAsync和使用代理Beginxx x Endxxx方法。
我明白了。有没有任何选项可以使WCF调用异步? – David 2013-04-09 17:11:22
这里有几个链接例子:http://stackoverflow.com/questions/781932/async-call-to-wcf-with-c – LouD 2013-04-09 18:13:32
一些直接的WCF链接在这里:http://msdn.microsoft.com/ en-us/library/ms730059.aspx,http://code.msdn.microsoft.com/windowsdesktop/How-to-Implement-a-WCF-2090bec8 – LouD 2013-04-09 18:20:47