Esempio n. 1
0
        public async Task RunRecursively(int deep, string url)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                LinkService linkService = new LinkService(unitOfWork);
                await Task.Run(() =>
                {
                    Thread.Sleep(500);

                    if (deep <= 0)
                    {
                        return;
                    }
                    if (deep == 1)
                    {
                        this.SingleIteration(url, linkService);
                    }
                    else
                    {
                        this.SingleIteration(url, linkService);
                        var linksFromPreviousIteration = linkService.GetAllLinksByIteration(linkService.GetCurrentIteration() - 1).ToList();
                        if (linksFromPreviousIteration.Count() != 0)
                        {
                            Parallel.ForEach <string>(linksFromPreviousIteration, (link) =>
                            {
                                Task t = RunRecursively(deep - 1, link);
                                t.Wait();
                            });
                        }
                    }
                });
            }
        }