Example #1
0
        public async Task <IEnumerable <Schedule> > FillTableRecurcieveAsyncTask(string website, NodeType nType)
        {
            var webLinks = await GetLinksRecursiveAsyncTask(website);

            List <Task <IEnumerable <Schedule> > > threads = new List <Task <IEnumerable <Schedule> > >();

            foreach (var webLink in webLinks)
            {
                threads.Add(Task.Factory.StartNew(async() =>
                {
                    string source;
                    try
                    {
                        source = Encoding.Default.GetString(await HClient.GetByteArrayAsync(webLink));
                    }
                    catch (Exception e)
                    {
                        ExceptionEvent?.Invoke(e);
                        return(new List <Schedule>());
                    }
                    return(FillTable(nType, source));
                }).Unwrap());
            }

            List <Schedule> result = new List <Schedule>();

            var tempResults = await Task.WhenAll(threads.ToArray());

            foreach (var tempResult in tempResults)
            {
                result.AddRange(tempResult);
            }

            return(result);
        }