我正在尝试使用 ManualResetEvent 进行阻塞,直到执行回调,但从未到达回调,即使我尝试在另一个线程上运行回调。
waitHandle = new ManualResetEvent(false);
DataServiceQueryer<MyEntity> dataServiceQueryer = new DataServiceQueryer<MyEntity>(dsQuery.Expression);
ThreadPool.QueueUserWorkItem(new WaitCallback(stateInfo =>
{
dataServiceQueryer.ExecuteQuery();
}));
// waits here forever
waitHandle.WaitOne();
public class DataServiceQueryer<T>
{
//field, properties
public void ExecuteQuery()
{
// this block is definitely executed
_asyncResult = _query.BeginExecute(new AsyncCallback(c =>
{
// this is never reached
QueryOperationResponse<T> result = _query.EndExecute(c) as QueryOperationResponse<T>;
MainPage.ListRecords = new ObservableCollection<T>(result) as ObservableCollectionEx<MyEntity>;
MainPage.waitHandle.Set();
}), _query);
// neither is this!
var test = _asyncResult.AsyncWaitHandle.WaitOne(0);
}
}
有什么建议么?我对为什么_asycResult
任务似乎永远不会发生感到最困惑。我将 Silverlight 4 与 EF4 和 devart Oracle dotConnect 提供程序一起使用。