Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 989499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:48:09+00:00 2026-05-16T05:48:09+00:00

hi; i try to run my codes. My program more slowly runnig. i need

  • 0

hi; i try to run my codes. My program more slowly runnig. i need to give performance also write less codes in GetAliSpReqs(), GetMaintData();GetAccess….GET(…

How can i write more effective below codes. They are too slow also not useful. forexample i try to write les than 1-2 line with GetAliSpReqs()? How can i ? please help me…

  public void LoadById(string SearchItem)
        {
            var myTechnicTasks = engTaskCtx.Tasks.Where(task => task.MyTechnicReference.StartsWith(SearchItem)).Select(task => new MyTask()
            {
                id = task.id,
                MyTechnicReference = task.MyTechnicReference,
                MPDReference = task.MPDReference,
                tasktypeid = task.tasktypeid,
                shortdesc = task.shortdesc,
                interval = task.interval,
                critical = task.critical,
                mandatory = task.mandatory,
                dupinsp = task.dupinsp,
                dualsystemmaint = task.dualsystemmaint,
                MPDSkill = task.MPDSkill,
                MPDCrew = task.MPDCrew,
                MPDAccessMH = task.MPDAccessMH,
                MPDTotalMH = task.MPDTotalMH,
                extratime = task.extratime,
                Team = task.Team,
                MaintData = EngGetCalculatedTaskField.GetMaintData(task.id),
                AliSpReqs = EngGetCalculatedTaskField.GetAliSpReqs(task.id),
                Access = EngGetCalculatedTaskField.GetAccess(task.id),
                preperation = task.preperation,
                longdesc = task.longdesc,
                applnotes = task.applnotes
            });
            MyTechnicTaskList = myTechnicTasks.ToList();
        }




    public static class EngGetCalculatedTaskField
    {
        private static TaskMaintenanceDataDataContext engTaskCtx { get; set; }
        public static string GetMaintData(int taskID)
        {
            try
            {
                using (TaskCardContext.TaskMaintenanceDataDataContext dc = new TaskCardContext.TaskMaintenanceDataDataContext())
                {
                    string maintenanceData = String.Empty;

                    foreach (var item in dc.TaskRelations.Where(tableRaletions => tableRaletions.TaskId == taskID && tableRaletions.RelTypeId == 12))
                    {
                        maintenanceData += item.RefMaintenance.shortdesc + "; ";
                    }

                    return maintenanceData.Substring(0, maintenanceData.Length - 2);
              }
            }
            catch
            {
                return String.Empty;
            }

        }
        public static string GetAliSpReqs(int taskID)
        {
            #region Old
            try
            {
                using (TaskCardContext.TaskMaintenanceDataDataContext dc = new            TaskCardContext.TaskMaintenanceDataDataContext())
                {
                    string aliSpReqs = String.Empty;

                    foreach (var item in dc.TaskRelations.Where(tableRaletions => tableRaletions.TaskId == taskID && tableRaletions.RelTypeId == 13))
                    {
                        aliSpReqs += item.RefAliSpReq.shortdesc + "; ";
                    }
                    return aliSpReqs.Substring(0, aliSpReqs.Length - 2);


                }
            }
            catch
            {
                return String.Empty;
            } 
            #endregion


        }
        public static string GetAccess(int taskID)
        {
            #region Old
            try
            {
                using (TaskCardContext.TaskMaintenanceDataDataContext dc = new TaskCardContext.TaskMaintenanceDataDataContext())
                {
                    string access = String.Empty;

                    foreach (var item in dc.TaskRelations.Where(tableRaletions => tableRaletions.TaskId == taskID && tableRaletions.RelTypeId == 15))
                    {
                        access += item.RefAccessPanel.shortdesc + "; ";
                    }
                    return access.Substring(0, access.Length - 2);


                }
            }
            catch
            {
                return String.Empty;
            } 
            #endregion

        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:48:10+00:00Added an answer on May 16, 2026 at 5:48 am

    Let’s take this bit of code as an example:

    string aliSpReqs = String.Empty;
    
    foreach (var item in dc.TaskRelations.Where(tableRaletions => 
                      tableRaletions.TaskId == taskID 
                      && tableRaletions.RelTypeId == 13))
    {
        aliSpReqs += item.RefAliSpReq.shortdesc + "; ";
    }
    return aliSpReqs.Substring(0, aliSpReqs.Length - 2);
    

    You’re concatenating strings in a loop. That’s a bad idea. Instead, try this (assuming .NET 4):

    var query = c.TaskRelations.Where(r => r.TaskId == taskID 
                                           && r.RelTypeId == 13))
                               .Select(r => r.RefAliSpReq.shortdesc);
    return string.Join("; ", query);
    

    In .NET 3.5 you’d need to use this instead:

    var query = c.TaskRelations.Where(r => r.TaskId == taskID 
                                           && r.RelTypeId == 13))
                               .Select(r => r.RefAliSpReq.shortdesc);
    return string.Join("; ", query.ToArray());
    

    Admittedly I can’t tell whether that’s actually what’s making this slow or not – but it could well be, if there are a lot of strings.

    As an aside, this is a terrible idea:

    catch
    {
        return String.Empty;
    }
    

    Catch specific exceptions instead – or in most cases, just let the exception propagate to the caller. At the very least you should log the exception so you know what’s going wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that being open source does not necessarily makes a program more/less secure
In my program, I need to run a external command in a Ubuntu environment
When I try to run the following code (from the REPL) in Clojure: (dotimes
When I try to run a .NET assembly ( boo.exe ) from a network
Every time I try to run a small application that uses a Derby DB
When I try to run a particular stored procedure on my MS SQL 2005
whenever I try to run something in Java, Eclipse changes into the PHP perspective.
I get a generic failure when I try to run: saslpasswd2 username This was
I have installed CherryPy 3.1.0,. Here is what happens when I try to run
I keep encountering this Debug assertions failed! error when I run my program in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.