Click here to Skip to main content
15,884,078 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

my c# code .
how to improve the performance in this following code snippet

public class SubmitUser : UserAction
{
    private ServiceFacade facade;

    public override string Name
    {
        get
        {
            return "Submit User";
        }
    }

    public SubmitUser(Ticket ticket)
        : base(ticket) { }


    protected override void Setup()
    {
        facade = ServiceFacade.GetInstance(User.AgentId,
            Ticket.Server.ToUrl(),
            null,
            @"NT AUTHORITY\SYSTEM",
            15000,
            "");


        Job Job = new Job
        {
            QueueName = Ticket.Name,
            DocumentName = "Document.doc",
            DocumentDisplayName = Ticket.DocName,
            ContentType = 0,
            Owner = Ticket.User.UserName,
            DomainName = Ticket.User.Domain,
            Pages = 1,
            Size = 1024,
            SubmittedDateTime = String.Format("{0:s}", DateTime.Now.ToString())
        };



        JobTicket = new JobTicket
        {
            JobPartId = Guid.NewGuid(),
            JobSpecXml = Job.ToString()
        };

        Ticket.JobPartId = JobTicket.JobPartId;
    }

    protected override void ExecuteAction()
    {
        try
        {
            facade.SubmitUs(JobTicket);

            ServicesFacade.UserServiceFacade userSer = new ServicesFacade.UserServiceFacade();

            var myUsers = userSer
                .GeUser(User.Token, Globals.LANG_EN, Globals.JSON, Globals.JSON)
                .OrderBy(j => j.SubmissionDate)
                .ToList();

            foreach (var job in myUsers)
            {
                if (job.JobParts != null)
                {
                    var jp = job.JobParts.SingleOrDefault(j => j.JobPartId == Ticket.JobPartId);
                    if (jp != null)
                    {
                        Ticket.JobId = job.JobId;
                    }
                }
            }
        }
        catch (Exception e)
        {
            StopWithError(e);
        }

    }
}


What I have tried:

How to imrpove the performance in this following code snippet
Posted
Updated 20-Dec-21 22:34pm
Comments
CHill60 21-Dec-21 4:21am    
What's the problem?

1 solution

Start by finding out what the current performance is in numeric terms: use the Stopwatch class[^] to execute that code in a tight loop a considerable number of times to give you a "baseline" speed to work against.

Then time individual elements to find where the slowest sections are: focus on those for performance improvements as they give the biggest rewards - reducing the the execution time by 50% for a section that uses 1% of the runtime isn't worth as mush as reducing the runtime by 10% of a section that uses 50%! Identifying bottlenecks is the key here.

Each time you make an improvement, quantify it: you have a set of starting point values, so use them to evaluate your changes. And remember, quite often the best improvements aren't "simpler code" but "better algorithms" - throwing code away and replacing it with a whole different way of working can give massive improvements (or make things significantly worse of course - that's why you need a baseline time to work against).

Good luck - this is not a simple task, and we can't help you in practice at all as we have no access to your data or systems: you need both as well as your code to get any meaningful improvements.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900