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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:03:56+00:00 2026-06-07T05:03:56+00:00

I’m creating a file processor for use in an intranet. I described it in

  • 0

I’m creating a file processor for use in an intranet.
I described it in another question – ERR_EMPTY_RESPONSE when processing a large number of files in ASP.Net using C#

Now, as suggested on above question’s answer, I’m trying to use threads to execute the file processing task.

But there is a problem. I need the newly created thread to write feedbacks to a component in page (asp:panel, or div, or whatever). Those feedbacks would be results from several database operations.

The application reads those txts, interprets each line of it, and insert data in database. Each line inserted in database must return a feedback, like “registry ‘regname’ inserted successfully”, or “i got problems inserting registry ‘regname’ in file ‘filename’, skipping to next registry”.

I did test with something very simple:

protected void DoImport()
{
    try
    {
        MainBody.Style.Add(HtmlTextWriterStyle.Cursor, "wait");

        int x = 0;
        while (x < 10000)
        {
            ReturnMessage(String.Format("Number {0}<hr />", x), ref pnlConfirms);
            x++;
        }
    }
    catch (Exception ex)
    {
        ReturnMessage(String.Format("<font style='color:red;'><b>FATAL ERROR DURING DATA IMPORT</b></font><br /><br /><font style='color:black;'><b>Message:</b></font><font style='color:orange;'> {0}</font><br />{1}", ex.Message, ex.StackTrace), ref pnlErrors);
    }
    finally
    {
        MainBody.Style.Add(HtmlTextWriterStyle.Cursor, "default");
    }
}

This function is called from Page_Load, and fills an asp:panel called “pnlConfirms” with a row of numbers, but all at once, on load.

I changed it to:

protected void DoImport()
{
    try
    {
        MainBody.Style.Add(HtmlTextWriterStyle.Cursor, "wait");
        ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork));
    }
    catch (Exception ex)
    {
        ReturnMessage(String.Format("<font style='color:red;'><b>FATAL ERROR DURING DATA IMPORT</b></font><br /><br /><font style='color:black;'><b>Message:</b></font><font style='color:orange;'> {0}</font><br />{1}", ex.Message, ex.StackTrace), ref pnlErrors);
    }
    finally
    {
        MainBody.Style.Add(HtmlTextWriterStyle.Cursor, "default");
    }
}

private void DoWork(Object stateInfo)
{
    int x = 0;
    while (x < 10000)
    {
        ReturnMessage(String.Format("Number {0}<hr />", x), ref pnlConfirms);
        x++;
    }
}

And both uses this function:

public void ReturnMessage(string message, ref Panel panel, bool reset = false)
{
    if (reset)
    {
        panel.Controls.Clear();
    }
    Label msg = new Label();
    msg.Attributes.Add("width", "100%");
    msg.Text = message;
    panel.Controls.Add(msg);
}

I need ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork)); to fill those asp:panels with feedbacks – like insertion errors and warnings.

My code already has those feedbacks under try...catch statements, but they’re not getting output to any asp:panel from threadpool (it works when invoked directly from DoImport() function, like in the first example I posted).

I’m doing something very wrong, but I can’t find out what (and I’m researching this for almost 2 weeks). Please, help!

  • 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-06-07T05:03:59+00:00Added an answer on June 7, 2026 at 5:03 am

    In ASP.NET, when a browser requests a page, that page is rendered and sent to the browser as soon as its processing finishes, so the browser will show the page as it’s finally rendered.

    According to your code you’re trying to render a page, show a wait cursor, and expect it’s shown on the browser and then, the cursor is changed by a default cursor. As I explained, independently from using or not additional threads, the page won’t be sent to the browser until it’s completely rendered. So you’l never see the wait cursor on the client side.

    The easiest wait to get what you’re trying to do is to use web services (traditional .asmx or WCF) and AJAX (jquery os ASP.NET AJAX).

    1) create a web service that does the processing

    2) create a page which is sent to the browser, and, using javascript (jQuery or ASP.NET AJAX) make a call to the web service, and show something to let the user know that the request is being processed. (a wait cursor, or even better an animated gif)

    3) when the process finishes, your javascript will get the responde from the web service, and you can update the page to let the user know the process has finished.

    if you don’t have experience on javascript, you can make most of this task using:

    • ScriptManager which can be used to create a javascript web service proxy for your client side (other interesting article) and is required for the rest of the controls

    • some javascript (or jquery) which can be use to update the “process running/ process finished hints” on the client side. I.e. when the call to the web service ends, you can use javascript to update the page using DOM, or load a new page or the same page with an special parameter to show the result of the process

    In this way you can do what you want:

    1) show a page in a state that shows the process is running

    2) show the same, or other page, in a state that shows the end of the process

    The trick is comunicating the browser with the server, and this can only be done using some of the available ajax techniques.

    Another typical technique is using jQuery.ajax, like explained in encosia.com

    According to the OP message, the process of all the files would be so slow that it would tiemout the web service call. If this is the case, you can use this solution:

    1) Create a web service that process one (or a batch) of the pending files, and returns at least the number of pending files when it finishes the processing of the current file (or batch).

    2) from the client side (javascript), call the web service. When it finishes, update the page showing the number of pending files, and, if this number is greater than zero, call the web service again.

    3) when the call to the web service returns 0 pending files, you can update the page to show the work is finished, and don’t call it any more.

    If you process all the files at once, there will be no feedback on the client side, and there will also be a timeout. Besides, IIS can decide to stop the working thread which is making the work. IIS does this for several reasons.

    A more reliable solution, but harder to implement, is:

    1) implement a Windows Service, that does the file processing

    2) implement a web service that returns the number of pending files (you can communicate the Windows Service and Web App indirectly using the file system, a database table or something like that)

    3) use a timer (ajax timer, or javascript setInterval) from your web page to poll the server every N seconds using the web service, until the number of pending files is 0.

    An even harder way to do this is hosting a WCF service in your Windows Service, instead of the indirect communication between your web app and windows service. This case is much more complicated because you need to use threads to do the work, and attend the calls to the wcf service. If you can use indirect communitacion it’s much easier to implemente. The dtabse table is a simple and effective solution: your working process updates a row a table whenever it process a file, and the web service reads the progress state from this table.

    There are many different soultions for a not so simple problem.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.