OS Name: Mac OS X
OS Version: 13.4
OS Platform: Darwin
RID: osx-arm64
.net core:Version: 8.0.1
I want to request an event stream url using the following code, which runs normally.
private async Task<IList<RepoInfo>> GetSearchResult(string url)
{
var repoList = new List<RepoInfo>();
using (var client = new HttpClient())
{
try
{
var stream = await client.GetStreamAsync(url);
using (var streamReader = new StreamReader(stream))
{
while (!streamReader.EndOfStream)
{
var m = streamReader.ReadLine();
if (m != null && m.StartsWith("data: {"filename":"package.json""))
{
var contentInfo = JsonSerializer.Deserialize<ContentInfo>(repoString);
repoList.Add(contentInfo.repo);
}
catch (Exception e)
{
Console.WriteLine(e.Message, "ddddd");
}
}
return repoList;
}
public async Task<IList<RepoInfo>> SearchDependencies(string searchName)
{
var url = this.BuildSearchUrl(searcheLib);
return await this.GetSearchResult(url);
}
private async Task ExcuteSearchGitLabSubAll(CommandOPtions commandOPtions)
{
List<RepoInfo> repoInfos = new List<RepoInfo>();
var packages = [];
foreach (var packageName in packages)
{
var result = await SearchDependencies(packageName);
if (result != null)
{
repoInfos.AddRange(result);
Console.WriteLine("------------{0},{1}", "completed!!", packageName);
}
}
Console.WriteLine("------------{0},{1}", "completed All!!", path);
}
However, if I want to execute it in parallel, the program will terminate without waiting for all tasks to finish.
private async Task ExcuteSearchGitLabAll(CommandOPtions commandOPtions)
{
var allLibs = Const.fileList;
List<RepoInfo> repos = new List<RepoInfo>();
await Parallel.ForEachAsync(allLibs, async (lib,token) =>
{
var result = await codeBaseService.SearchDependencies(lib);
repos.AddRange(result);
});
});
Console.WriteLine("------------{0}", "completed All!!");
}