我上传和下搜谷歌,但我找不到关于该主题的任何适当信息。
我想做的是:
如何使用C#3.5做到这一点?
更新:
查看:
private void OnTextChanged(...)
{
if (SearchFormatEvent != null)
{
ICollection<object> collection = SearchFormatEvent("MySearchString");
// Do stuff on the returned collection
}
}
SearchProvider :
// This is the delegate invoked for the async search taking the searchstring typed by the user
public delegate ICollection<object> SearchInputTextStrategy<T>(string param);
public class SearchProvider : ISearchProvider
{
private ITextView _view;
private SearchInputTextStrategy<object> searchInputDelegate;
public SearchProvider(ITextView view)
{
_view = view;
_view.SearchFormatEvent += new ConstructSearchFormatDelegate(CostructSearchFormat);
}
private string SearchFormat(string param)
{
// compute string
return string.Empty; //...
}
public ICollection<object> CostructSearchFormat(string param)
{
var searchfilter = SearchFormat(param);
IAsyncResult pendingOperation = searchInputDelegate.BeginInvoke("searchfilter",null,null);
// How can I cancel the Async delegate ?
ICollection<object> result = searchInputDelegate.EndInvoke(pendingOperation);
return result;
}
}
答案 0 :(得分:5)
切换到BackGroudWorker,支持您所需的一切(NoUI阻止,取消等,进度报告......)
答案 1 :(得分:1)
查看CancellationTokenSource和CancellationToken,它是一种线程安全的信号取消方法。
您使用CancellationTokenSource
向CancellationToken
的所有所有者(在您的情况下为搜索主题)发出取消信号