Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
AnswerRe: Application Server and Connection Method Pin
Mycroft Holmes9-Apr-19 12:29
professionalMycroft Holmes9-Apr-19 12:29 
QuestionIPV6 Compatibility Pin
chain singh aanjana7-Apr-19 20:37
chain singh aanjana7-Apr-19 20:37 
AnswerRe: IPV6 Compatibility Pin
Gerry Schmitz8-Apr-19 5:47
mveGerry Schmitz8-Apr-19 5:47 
QuestionHow to add second column to a listBox component? Pin
Member 140558797-Apr-19 9:13
Member 140558797-Apr-19 9:13 
AnswerRe: How to add second column to a listBox component? Pin
Mycroft Holmes7-Apr-19 12:27
professionalMycroft Holmes7-Apr-19 12:27 
AnswerRe: How to add second column to a listBox component? Pin
BillWoodruff7-Apr-19 16:27
professionalBillWoodruff7-Apr-19 16:27 
AnswerRe: How to add second column to a listBox component? Pin
Gerry Schmitz8-Apr-19 5:20
mveGerry Schmitz8-Apr-19 5:20 
QuestionIterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol7-Apr-19 8:15
Mou_kol7-Apr-19 8:15 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn7-Apr-19 15:51
sitebuilderLuc Pattyn7-Apr-19 15:51 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol8-Apr-19 9:13
Mou_kol8-Apr-19 9:13 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn8-Apr-19 9:15
sitebuilderLuc Pattyn8-Apr-19 9:15 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Eddy Vluggen8-Apr-19 0:23
professionalEddy Vluggen8-Apr-19 0:23 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol8-Apr-19 9:14
Mou_kol8-Apr-19 9:14 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Eddy Vluggen9-Apr-19 2:02
professionalEddy Vluggen9-Apr-19 2:02 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Gerry Schmitz8-Apr-19 5:39
mveGerry Schmitz8-Apr-19 5:39 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn8-Apr-19 11:50
sitebuilderLuc Pattyn8-Apr-19 11:50 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol9-Apr-19 9:14
Mou_kol9-Apr-19 9:14 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol11-Apr-19 8:58
Mou_kol11-Apr-19 8:58 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn11-Apr-19 9:17
sitebuilderLuc Pattyn11-Apr-19 9:17 
QuestionHow to do three join between three list Pin
Mou_kol7-Apr-19 8:12
Mou_kol7-Apr-19 8:12 
AnswerRe: How to do three join between three list Pin
User 41802549-Apr-19 3:22
User 41802549-Apr-19 3:22 
QuestionRepeated join causing poor performance in for loop Pin
Mou_kol7-Apr-19 8:10
Mou_kol7-Apr-19 8:10 
My problem is that when there are 50 or 100 iterations in for loop and doing repeated join between list & datatable, then my code takes long time to run about 10 minute.

C#
if (lst_Broker_BrokerBogey_collection.Any())
{
    foreach (var objbrokerBrogeyData in lst_Broker_BrokerBogey_collection)
    {

        string brokerBogeypath = File.Exists(@Path.Combine(ConfigurationManager.AppSettings["DBPath"].ToString(), cmbTicker.Text, "###~$$$~Bogey.xml".Replace("###", cmbTicker.Text).Trim().Replace("$$$", objbrokerBrogeyData.Broker).Trim())) ?
        @Path.Combine(ConfigurationManager.AppSettings["DBPath"].ToString(), cmbTicker.Text, "###~$$$~Bogey.xml".Replace("###", cmbTicker.Text).Trim().Replace("$$$", objbrokerBrogeyData.Broker).Trim()) : ""; ;

        if (!String.IsNullOrEmpty(brokerBogeypath))
        {
            bool selectedBroker = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select")).Equals("True") ? true : false;
            if (selectedBroker)
            {
                RDSS_Workbench.QcVerticalViewNew.QcVerticalViewNewProcess.BrokerCodeBrokerNameBrokerBogey objBrokerCodeBrokerNameBrokerBogey
                    = new QcVerticalViewNew.QcVerticalViewNewProcess.BrokerCodeBrokerNameBrokerBogey();

                objBrokerCodeBrokerNameBrokerBogey.BrokerCode = objbrokerBrogeyData.Broker;
                objBrokerCodeBrokerNameBrokerBogey.IsAllowEstimate = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select Estim.")).Equals("True") ? true : false; //objbrokerBrogeyData._willpassEstimatePeriods;
                objBrokerCodeBrokerNameBrokerBogey.IsHistoric = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Historical")).Equals("True") ? true : false; //objbrokerBrogeyData._followHistoricalData;
                objBrokerCodeBrokerNameBrokerBogey.ReviseDate = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Model Date"));
                objBrokerCodeBrokerNameBrokerBogey.BrokerEarnings = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Earnings"));

                DataTable GeneralBrokerDt = new DataTable();
                GeneralBrokerDt = objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GetBrokerBogey(@brokerBogeypath).Tables[2]; //objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt.Tables[2];

                List<QCHelper> qclist = new List<QCHelper>();

                qclist = (from cf in cfToggleList
                          join broker in GeneralBrokerDt.AsEnumerable()
                       on new { val = cf.Section.Trim().ToUpper(), val1 = cf.Li.Trim().ToUpper(), val2 = cf.StandardDate.Replace("A", "").Replace("E", "").Trim().ToUpper() }
                       equals new { val = broker.Field<string>("TabName").Trim().ToUpper(), val1 = broker.Field<string>("StandardLineitem").Trim().ToUpper(), val2 = broker.Field<string>("StandardDate").Replace("A", "").Replace("E", "").Trim().ToUpper() }
                       into tempJoin
                          from leftJoin in tempJoin.DefaultIfEmpty()
                          where cf.Broker == objBrokerCodeBrokerNameBrokerBogey.BrokerCode
                          select new QCHelper()
                          {
                              Broker = cf.Broker,
                              BrokerName = cf.BrokerName,
                              Section = cf.Section,
                              BrokerEarnings = objBrokerCodeBrokerNameBrokerBogey.BrokerEarnings,
                              Li = cf.Li,
                              StandardDate = leftJoin == null ? cf.StandardDate : leftJoin.Field<string>("StandardDate"),
                              xFundCode = cf.xFundCode,
                              StandardValue = leftJoin == null ? string.Empty : leftJoin.Field<string>("StandardValue"),
                              IsAllowEstimate = objBrokerCodeBrokerNameBrokerBogey.IsAllowEstimate,
                              ReviseDate = objBrokerCodeBrokerNameBrokerBogey.ReviseDate
                          }).ToList<QCHelper>();

                GeneralBrokerDt.Dispose();
                GeneralBrokerDt = null;
                objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt.Dispose();
                objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt = null;

                if (qclist.Count > 0)
                    lstBorkerWiseData.AddRange(qclist);

                qclist = null;
                objBrokerCodeBrokerNameBrokerBogey = null;
            }
        }
    }


This is my list lst_Broker_BrokerBogey_collection in which I need to iterate. brokerBogeypath will have multiple different file location in loop.

This line:

C#
bool selectedBroker = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select")).Equals("True") ? true : false;


dtdgvBrokers is datagridview and in selectedBroker variable will have true false value based on grid select value.

If selected broker has true value, then load datatable GeneralBrokerDt. GetBrokerBogey() function will load data from different xml file in each for loop iteration.

in next line
C#
qclist = (from cf in cfToggleList
join broker in GeneralBrokerDt.AsEnumerable()


I am joining list cfToggleList and datatable GeneralBrokerDt.

Can you review it for performance and best coding practices?
AnswerRe: Repeated join causing poor performance in for loop Pin
jschell7-Apr-19 8:57
jschell7-Apr-19 8:57 
GeneralRe: Repeated join causing poor performance in for loop Pin
Mou_kol8-Apr-19 9:07
Mou_kol8-Apr-19 9:07 
AnswerRe: Repeated join causing poor performance in for loop Pin
Luc Pattyn7-Apr-19 15:44
sitebuilderLuc Pattyn7-Apr-19 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.