Looping Async Task List in C#

后端 未结 4 1254
半阙折子戏
半阙折子戏 2021-01-22 07:26

I am trying to parse data from several websites continuously. I would like this action to be preformed individually in a loop in an asynchronous manner until the program is clos

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-22 07:39

    It's easy enough to create a method to loop continuously and parse a single site over and over again. Once you have that method, you can call it once on each site in the list:

    private async void ParseSite(Site s)
    {
        while (true)
        {
            await s.ParseData();
        }
    }
    
    public void ParseAll(List siteList)
    {
        foreach (var site in siteList)
        {
            ParseSite(site);
        }
    }
    

提交回复
热议问题