Question

Je suis en cours d'exécution 12 fils .function ces fils qui appellent est de ne pas avoir une serrure sur certains object.but encore ces fils prennent trop de temps. (16 minutes) .Chaque fil analyse syntaxique ially un document xml qui est en cours d'exécution bien si elle est exécutée indiviually.is ce problème en raison d'une raison liée max pas de fils fournis par édition express ou un blocage dn par édition express.


code de func WHIC chaque thread appelle est donnée ci-dessous. chaque fil est donnée différente rssfeed (urladdress)

public static class RssFileReader
{
    public static Rss GetRssDocumentData(string rssFeed)
    {
        Console.WriteLine("thread in RssFileReader: " + Thread.CurrentThread.Name);

        IFormatProvider culture = new CultureInfo("fr-FR", true);

        Rss rssDocumentObject=new Rss();
        XmlDocument documentObj = new XmlDocument();
        try
        {
            documentObj.Load(HttpClient.GetWebResponse(@rssFeed, null, null, 1200000, @"http://www.sahil.com").GetResponseStream());
        }
        catch(Exception e)
        {
            e.Source = "RssFileReader:Loading xmldocument object";
            throw;
        }
        try
        {
            XmlNodeList channelList = documentObj.GetElementsByTagName("channel");
            for (int k = 0; k < channelList.Count; k++)
            {

                rssDocumentObject.ListOfChannel.Add(new Channel());
                int noOfItemInChannel = -1;
                //XmlNodeList itemList = channelList[k].ChildNodes;
                for (int i = 0; i < channelList[k].ChildNodes.Count; i++)
                {


                    switch (channelList[k].ChildNodes[i].Name)
                    {

                        case "item":
                            noOfItemInChannel++;
                            XmlNodeList xmlChildNodeOfItem = channelList[k].ChildNodes[i].ChildNodes;
                            //debugging
                            //Console.WriteLine("Thread Name in item in RssFileReader" + Thread.CurrentThread.Name);

                            rssDocumentObject.ListOfChannel[k].ListOfItem.Add(new Item());

                            for (int j = 0; j < xmlChildNodeOfItem.Count; j++)
                            {
                                switch (xmlChildNodeOfItem[j].Name)
                                {
                                    case "title":
                                        rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemTitle.InnerText = xmlChildNodeOfItem[j].InnerText;
                                        break;
                                    case "link":
                                        rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemLink.InnerText = xmlChildNodeOfItem[j].InnerText;
                                        break;
                                    case "description":
                                        rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemDescription.InnerText = xmlChildNodeOfItem[j].InnerText;
                                        break;
                                    case "pubDate":
                                        try
                                        {
                                            string dateTimeTemp = xmlChildNodeOfItem[j].InnerText;
                                            char[] splitCharArray = new char[1];
                                            splitCharArray[0] = ' ';
                                            string[] splitedDateTimeTemp = dateTimeTemp.Split(splitCharArray);
                                            string RFC822 = "ddd,ddMMMyyyyHH:mm:ss";
                                            rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemPubDate.PublicationDate = DateTime.ParseExact(splitedDateTimeTemp[0] + splitedDateTimeTemp[1] + splitedDateTimeTemp[2] + splitedDateTimeTemp[3] + splitedDateTimeTemp[4], RFC822, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
                                        }
                                        //exception not rethrown default date is assigned 
                                        catch (Exception e)
                                        {
                                            //Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);
                                        }
                                        break;
                                    case "guid":
                                        rssDocumentObject.ListOfChannel[k].ListOfItem[noOfItemInChannel].ItemGuid.InnerText = xmlChildNodeOfItem[j].InnerText;
                                        break;


                                }
                            }
                            break;
                        case "title":
                            rssDocumentObject.ListOfChannel[k].ChannelTitle.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "description":
                            rssDocumentObject.ListOfChannel[k].ChannelDescription.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "link":
                            rssDocumentObject.ListOfChannel[k].ChannelLink.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;

                        case "language":
                            rssDocumentObject.ListOfChannel[k].ChannelLanguage.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "pubDate":
                            try
                            {
                                string dateTimeTempForChannel = channelList[k].ChildNodes[i].InnerText;
                                char[] splitCharArrayForChannel = new char[1];
                                splitCharArrayForChannel[0] = ' ';
                                string[] splitedDateTimeTempForChannel = dateTimeTempForChannel.Split(splitCharArrayForChannel);
                                string formatStringForChannel = "ddd,ddMMMyyyyHH:mm:ss";
                                rssDocumentObject.ListOfChannel[k].ChannelPubDate.PublicationDate = DateTime.ParseExact(splitedDateTimeTempForChannel[0] + splitedDateTimeTempForChannel[1] + splitedDateTimeTempForChannel[2] + splitedDateTimeTempForChannel[3] + splitedDateTimeTempForChannel[4], formatStringForChannel, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
                            }
                            //exception not rethrown default date is assigned 
                            catch (Exception e)
                            {
                                //Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);

                            }
                            break;
                        case "lastBuildDate":
                            try
                            {
                                string dateTimeTempForChannel = channelList[k].ChildNodes[i].InnerText;
                                char[] splitCharArrayForChannel = new char[1];
                                splitCharArrayForChannel[0] = ' ';
                                string formatStringForChannel = "ddd,ddMMMyyyyHH:mm:ss";

                                string[] splitedDateTimeTempForChannel = dateTimeTempForChannel.Split(splitCharArrayForChannel);
                                rssDocumentObject.ListOfChannel[k].ChannelLastBuildDate.LastBldDate = DateTime.ParseExact(splitedDateTimeTempForChannel[0] + splitedDateTimeTempForChannel[1] + splitedDateTimeTempForChannel[2] + splitedDateTimeTempForChannel[3] + splitedDateTimeTempForChannel[4], formatStringForChannel, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
                            }
                            //exception not rethrown default date is assigned 
                            catch (Exception e)
                            {
                                //Console.WriteLine("Exception while formatting string to datetime in rssFileReader():" + e);

                            }

                            break;

                        case "docs":
                            rssDocumentObject.ListOfChannel[k].ChannelDocs.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "generator":
                            rssDocumentObject.ListOfChannel[k].ChannelGenerator.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "managingEditor":
                            rssDocumentObject.ListOfChannel[k].ChannelManagingEditor.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "webMaster":
                            rssDocumentObject.ListOfChannel[k].ChannelWebMaster.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;
                        case "ttl":
                            rssDocumentObject.ListOfChannel[k].ChannelTtl.InnerText = channelList[k].ChildNodes[i].InnerText;
                            break;

                    }
                }


            }
        }
        catch(Exception e)
        {
            e.Source = "RssFileReader:Reading xml document object data to rss object";
            throw;
        }
        Console.WriteLine("    Thread out RssFilereader :" + Thread.CurrentThread.Name);
        return rssDocumentObject;
    }
}

Note: le débogage -Alors je suis arrivé à savoir que la prise du temps lors du chargement de document XML. est-il une limite imposée sur le système pour le nombre d'objets WebRequest?

Était-ce utile?

La solution 2

il prenait le temps quand je suis en cours d'exécution de l'application, il console pour les tests. raison tant de temps nécessaire bloquait io à cause des états d'impression pour le débogage.

Autres conseils

Si vous utilisez la fonctionnalité des requêtes web au même serveur, ceux-ci sont étranglées par défaut à deux connexions à la fois.

Vous êtes alors à défaut de disposer de la réponse et le flux de réponse, ce qui signifie qu'il va attendre jusqu'à ce qu'il soit nettoyé à libérer la connexion pour l'utiliser ailleurs. Modifiez votre code de chargement:

    try
    {
        // Removed unnecessary @ signs
        using (WebResponse response = HttpClient.GetWebResponse(
                  rssFeed, null, null, 1200000, "http://www.sahil.com"))
        using (Stream responseStream = response.GetResponseStream())
        {
            documentObj.Load(responseStream);
        }
    }
    catch(Exception e)
    {
        e.Source = "RssFileReader:Loading xmldocument object";
        throw;
    }

Il est possible que vous ne devez fermer la réponse Web - que le flux sera pris en charge en fermant la réponse - mais il vaut mieux être sûr

.

Vous aurez toujours que deux fils en utilisant les connexions au même serveur en même temps (par défaut, pour non-ASP.NET, vous pouvez modifier vous-même en utilisant ServicePointManager.DefaultConnectionLimit ou

scroll top