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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:59:09+00:00 2026-05-27T20:59:09+00:00

I have a system whereby users can upload sometimes large(100-200 MB) files from within

  • 0

I have a system whereby users can upload sometimes large(100-200 MB) files from within an MVC3 application. I would like to not block the UI while the file is uploading, and after some research, it looked like the new AsyncController might let me do what I’m trying to do. Problem is – every example I have seen isn’t really doing the same thing, so I seem to be missing one crucial piece. After much futzing and fiddling, here’s my current code:

public void CreateAsync(int CompanyId, FormCollection fc)
    {
        UserProfile up = new UserRepository().GetUserProfile(User.Identity.Name);
        int companyId = CompanyId;
        // make sure we got a file..
        if (Request.Files.Count < 1)
        {
            RedirectToAction("Create");
        }

        HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;
        if (hpf.ContentLength > 0)
        {
            AsyncManager.OutstandingOperations.Increment();

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (o, e) =>
                {
                    string fileName = hpf.FileName;
                    AsyncManager.Parameters["recipientId"] = up.id;
                    AsyncManager.Parameters["fileName"] = fileName;
                };
            worker.RunWorkerCompleted += (o, e) => { AsyncManager.OutstandingOperations.Decrement(); };
            worker.RunWorkerAsync();

        }

        RedirectToAction("Uploading");
    }

public void CreateCompleted(int recipientId, string fileName)
    {
        SystemMessage msg = new SystemMessage();
        msg.IsRead = false;
        msg.Message = "Your file " + fileName + " has finished uploading.";
        msg.MessageTypeId = 1;
        msg.RecipientId = recipientId;
        msg.SendDate = DateTime.Now;
        SystemMessageRepository.AddMessage(msg);
    }

    public ActionResult Uploading()
    {
        return View();
    }

Now the idea here is to have the user submit the file, call the background process which will do a bunch of things (for testing purposes is just pulling the filename for now), while directing them to the Uploading view which simply says “your file is uploading…carry on and we’ll notify you when it’s ready”. The CreateCompleted method is handling that notification by inserting a message into the users’s message queue.

So the problem is, I never get the Uploading view. Instead I get a blank Create view. I can’t figure out why. Is it because the CreateCompleted method is getting called which shows the Create view? Why would it do that if it’s returning void? I just want it to execute silently in the background, insert a message and stop.

So is this the right approach to take at ALL? my whole reason for doing it is with some network speeds, it can take 30 minutes to upload a file and in its current version, it blocks the entire application until it’s complete. I’d rather not use something like a popup window if I can avoid it, since that gets into a bunch of support issues with popup-blocking scripts, etc.

Anyway – I am out of ideas. Suggestions? Help? Alternate methods I might consider?

Thanks in advance.

  • 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-27T20:59:10+00:00Added an answer on May 27, 2026 at 8:59 pm

    You are doing it all wrong here. Assume that your action name is Create.

    1. CreateAsync will catch the request and should be a void method and returns nothing. If you have attributes, you should apply them to this method.
    2. CreateCompleted is your method which you should treat as a standard controller action method and you should return your ActionResult inside this method.

    Here is a simple example for you:

    [HttpPost]
    public void CreateAsync(int id) { 
    
        AsyncManager.OutstandingOperations.Increment();
    
        var task = Task<double>.Factory.StartNew(() => {
    
            double foo = 0;
    
            for(var i = 0;i < 1000; i++) { 
                foo += Math.Sqrt(i);
            }
    
            return foo;
    
        }).ContinueWith(t => {
            if (!t.IsFaulted) {
    
                AsyncManager.Parameters["headers1"] = t.Result;
            }
            else if (t.IsFaulted && t.Exception != null) {
    
                AsyncManager.Parameters["error"] = t.Exception;
            }
    
            AsyncManager.OutstandingOperations.Decrement();
        });
    
    }
    
    public ActionResult CreateCompleted(double headers1, Exception error) { 
    
        if(error != null)
            throw error;
    
        //Do what you need to do here
    
        return RedirectToAction("Index");
    }
    

    Also keep in mind that this method will still block the till the operation is completed. This is not a “fire and forget” type async operation.

    For more info, have a look:

    Using an Asynchronous Controller in ASP.NET MVC

    Edit

    What you want here is something like the below code. Forget about all the AsyncController stuff and this is your create action post method:

        [HttpPost]
        public ActionResult About() {
    
            Task.Factory.StartNew(() => {
    
                System.Threading.Thread.Sleep(10000);
    
                if (!System.IO.Directory.Exists(Server.MapPath("~/FooBar")))
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/FooBar"));
    
                System.IO.File.Create(Server.MapPath("~/FooBar/foo.txt"));
    
            });
    
            return RedirectToAction("Index");
        }
    

    Notice that I waited 10 seconds there in order to make it real. After you make the post, you will see the it will return immediately without waiting. Then, open up the root folder of you app and watch. You will notice that a folder and file will be created after 10 seconds.

    But (a big one), here, there is no exception handling, a logic how to notify user, etc.

    If I were you, I would look at a different approach here or make the user suffer and wait.

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

Sidebar

Related Questions

I've built a system whereby users can start a project and upload files to
I have a system whereby a user can view categories that they've subscribed to
I am currently working a system whereby my users can pay for items that
I have a system whereby an administrator enters in the IT credentials for users
I have an application which models the electrical distribution of a system whereby if
I have a system similar to BB code whereby text within two tags is
I have a web application where users can create topics and also comment on
I have designed an e-commerce system whereby I have products which can belong to
I have an address finder system whereby a user enters a postcode, if postcode
As many of you probably know, online banks nowadays have a security system whereby

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.