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 7703685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:30:55+00:00 2026-05-31T23:30:55+00:00

I have a function which is taking a lot of time to execute in

  • 0

I have a function which is taking a lot of time to execute in a web application.

I have tested this with a profiler and by my logging.

I have other functions running in the same pageload.

What is a best way to display the rest of the values from those functions and keep this function in a thread and display it in a label when it finishes?

This function is used to get events in application which takes time.

private void getEventErrors()
    {
        EventLog eventLog = new EventLog("Application", ".");

        getEvents(eventLog.Entries);
    }

private void getEvents(EventLogEntryCollection eventLogEntryCollection)
    {
        int errorEvents = 0;

        foreach (EventLogEntry logEntry in eventLogEntryCollection)
        {
            if (logEntry.Source.Equals("XYZ"))
            {
                DateTime variable = Convert.ToDateTime(logEntry.TimeWritten);
                long eventTimeTicks = (variable.Ticks);
                long eventTimeUTC = (eventTimeTicks - 621355968000000000) / 10000000;

                long presentDayTicks = DateTime.Now.Ticks;
                long daysBackSeconds = ((presentDayTicks - 864000000000) - 621355968000000000) / 10000000;


                if (eventTimeUTC > daysBackSeconds)
                {
                    if (logEntry.EntryType.ToString() == "Error")
                    {
                        errorEvents = errorEvents + 1;
                    }                        
                }
            }
        }
        btn_Link_Event_Errors_Val.Text = errorEvents.ToString(GUIUtility.TWO_DECIMAL_PT_FORMAT);            
        if (errorEvents == 0)
        {
            lbl_EventErrorColor.Attributes.Clear();
            lbl_EventErrorColor.Attributes.Add("class", "green");
        }
        else
        {
            lbl_EventErrorColor.Attributes.Clear();
            lbl_EventErrorColor.Attributes.Add("class", "red");
        }
    }

I have 3 functions in the pageload event, two to get the values from the DB and the other one is shown above.

Should both these functions be service calls?

What i wanted was, the page should load fast and if there is a function taking a lot of time it should run in the background and display when done and in the process if the user want to navigate to a new page it should kill it and move on.

  • 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-31T23:30:56+00:00Added an answer on May 31, 2026 at 11:30 pm

    If you have a function that is running in a separate thread in ASP.NET, you may want to consider moving it to a service. There are many reason for this

    See this answer (one of many on SO) for why running long running tasks in ASP.NET is not always a good idea.

    One option for the service is to use WCF. You can get started here. Your service could implement a method, say GetEvents() which you could use to pull your events. That way you won’t tie up your page waiting for this process to complete (using AJAX of course). Also, this allows you to change your implementation of GetEvents() without touching your code on your website.

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

Sidebar

Related Questions

here i have one function which is call many times in one application this
I have a function which calculates distance from database records. This function is called
I have a lot of functions which are currently overloaded to operate on int
I'm taking some information from some variables I have already defined outside this function
I have a sorta unique question. There is a web application which takes 5.57mbs
I have a function that's taking a long time to run. When I profile
I have a function which parses one string into two strings. In C# I
I have a function which searches an STL container then returns the iterator when
I have an function which decodes the encoded base64 data in binary data but
I have a function which gets a key from the user and generates a

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.