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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:13:11+00:00 2026-05-21T14:13:11+00:00

I’m just starting to learn ASP.NET MVC. The website I’m working on requires the

  • 0

I’m just starting to learn ASP.NET MVC. The website I’m working on requires the user to upload XML files which are loaded into a SQL database through NHibernate. This is working ok now with a small XML file, but once I tried a larger file I started having problems.

When I upload a larger file it takes a while for the data to be written to the database, so on the user’s end they get stuck “waiting for local host .. ” until the database write is complete and the Upload() action method returns a view.

Instead I’d like to set something up like most of the popular movie upload sites, where once the user uploads the file they are immediately sent to another page with a message that says something like “Your upload is being processed please come back later”.

I’ve done a little with multi-threading, but I hardly feel like I know what I am doing. Although, just now I seemed to have gotten my siteworking the way I want using System.Threading.ThreadPool.

Is using the thread pool like this the best way to approach this problem?

Here’s my Upload() action method.

public ActionResult Upload(int id)
{
    //check the type of request
    if (Request.RequestType == "GET")
        {
            //get GET show the upload form
            return View();
        }
        else if (Request.RequestType == "POST")
        {
            //if POST process uploaded file data
            if (Request.Files.Count == 1)
            {
                //copy the upload stream into a memory stream
                System.IO.MemoryStream memStream = new System.IO.MemoryStream();
                Request.Files[0].InputStream.CopyTo(memStream);

                //send the the memorystream, id, and username to a new Thread pool work item
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(WriteUploadToDb), new WriteUploadToDbData(id, memStream,User.Identity.Name));

                //send the user to a page
                ViewBag.Message = "Your file is being processed. Please come back later...";
                return RedirectToAction("Reports", new { ID = id });
            }
            else
            {
                throw new Exception("Multiple report files uploaded!");
            }
        }
    }

And here’s my WriteUploadToDb() method which is run on the ThreadPool.

private static void WriteUploadToDb(object obj)
    {
        WriteUploadToDbData updateData = (WriteUploadToDbData)obj;

        //resets the stream position
        updateData.Data.Position = 0;

        //creates a new Nhibernate session
        using (var session = MvcApplication.SessionFactory.OpenSession())
        {
            using (var trans = session.BeginTransaction())
            {
                var proj = session.Get<Project>(updateData.ProjectID);

                //adds the xml data into the Project
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                xmlDoc.Load(updateData.Data);
                proj.AddReport(xmlDoc, updateData.UserName);

                //saves the project to the db
                session.Update(proj);
                trans.Commit();
            }
        }

        //disposes the memory stream
        updateData.Data.Dispose();
    }
  • 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-21T14:13:11+00:00Added an answer on May 21, 2026 at 2:13 pm

    Depends on the volume you’re doing this at.

    For low to modest volume, kicking off an async thread to complete the work is fine. However, a given web server can only process so many threads (the thread pool has a finite, though configurable, size).

    For high volume applications I prefer to have the web server only handle web requests and offload any async processing to another server. This can be accomplished e.g. using MSMQ or by writing to a log file that another server picks up and processes (the later is commonly used in very high volume applications since writing to a file is a very fast and very reliable process).

    The reason I prefer to go this route is that I can scale to handle incoming web service / website requests independently from the processing of async work items, allowing for more control over the scale out.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
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.