我正在努力创建一个基本上为我玩游戏的应用程序.它形成突袭,加入突袭,然后启动突袭.我试图异步完成这一切.
一些背景:FormRaidAsync,JoinRaidAsync和LaunchRaidAsync都会发出Web请求.方法本身也设置为异步,但是当我运行程序时,它只加入大约2-3个帐户/秒.
我做错了什么,或async/await不一定在新线程上运行每个请求?如果是这种情况,我如何调整此代码以接近10 /秒的速率加入帐户?我是否必须使用其他形式的多线程来同时发出更多请求?
感谢大家.如果需要更多细节,请告诉我.
public async Task<string> StartRaidAsync()
{
string raid_id = String.Empty;
try
{
raid_id = await this.Helper.FormRaidAsync(this.TargetRaid.Id, this.Former.Id, this.TargetRaid.IsBossRaid).ConfigureAwait(false);
Console.WriteLine("Formed raid with {0}.", this.Former.Name);
List<Task> joinTasks = new List<Task>();
foreach (var joiner in this.Joiners)
{
try
{
joinTasks.Add(this.Helper.JoinRaidAsync(raid_id, joiner.Id));
}
catch (Exception) // Not sure which exceptions to catch yet.
{
Console.WriteLine("Error joining {0}. Skipped.", joiner.Name);
}
}
Task.WaitAll(joinTasks.ToArray());
await this.Helper.LaunchRaidAsync(raid_id, this.Former.Id).ConfigureAwait(false);
Console.WriteLine("{0} launched raid.", this.Former.Name);
}
catch (Exception) // Not sure which exceptions to catch yet. …Run Code Online (Sandbox Code Playgroud)