いくつかの I/O Completion ポートが完了するのを待つ最善の方法を見つけようとしています。
このシナリオでは、MVC3 Web アプリを使用しているとしましょう。(私の理解では、ここで I/O Completion ポートを使用することをお勧めします。これにより、元のスレッドを IIS に戻して他の要求にサービスを提供できます)
ID の配列があり、ネットワーク呼び出しから各 ID のオブジェクトを取得したいとします。
この同期メソッドを並列化する最良の方法は何ですか?
public class MyController: Controller
{
public ActionResult Index(IEnumerable<int> ids)
{
ids.Select(id => _context.CreateQuery<Order>("Orders")
.First(o => o.id == id));
DataServiceQuery<Order> query = _context.CreateQuery<Order>("Orders");
return Json(query);
}
private DataServiceContext _context; //let's ignore how this would be populated
}
私はそれが次のように始まることを知っています:
public class MyController: AsyncController
{
public void IndexAsync(IEnumerable<int> ids)
{
// magic here...
AsyncManager.Sync(() => AsyncManager.Parameters["orders"] = orders);
}
public ActionResult IndexCompleted(IEnumerable<Order> orders)
{
return Json(orders);
}
private DataServiceContext _context; //let's ignore how this would be populated
}
DataServiceContext.BeginExecuteメソッド を使用する必要がありますか? DataServiceContext.BeginExecuteBatch ? 私が使用しているデータ サービスは、一度に 1 つのレコードしか取得できません (これは私の制御を超えています)。これらの個々のクエリを並行して実行したいと考えています。