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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:03:17+00:00 2026-06-14T17:03:17+00:00

For testing purposes, I am using this directly inside of a razor block in

  • 0

For testing purposes, I am using this directly inside of a razor block in a .cshtml page.

@functions{
    public class Inline
    {
        public HttpResponseBase r { get; set; }
        public int Id { get; set; }
        public List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();

        public void Writer(HttpResponseBase response)
        {
            this.r = response;
            tasks.Add(System.Threading.Tasks.Task.Factory.StartNew(
                    () =>
                    {
                        while (true)
                        {
                            r.Write("<span>Hello</span>");
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
            ));
        }
    }
}

@{
    var inL = new Inline();
    inL.Writer(Response);
}

I had expected it to write a span with the text “Hello” once every second. It will write “Hello” once sometimes, but not every time or even most times. Why isn’t this task long running?

  • 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-14T17:03:19+00:00Added an answer on June 14, 2026 at 5:03 pm

    The reason you are seeing different result is because the task is running asynchronously and if the response object is completed before your task gets a chance to write on it, the taks will throw exception and it will terminate the only way you can do this is if you add Task.WaitAll() at the end of the Writer() method.

    This will work but the page will not stop loading content.

    this.r = response;
    tasks.Add(System.Threading.Tasks.Task.Factory.StartNew(
            () =>
            {
                while (true)
                {
                    r.Write("<span>Hello</span>");
                    r.Flush(); // this will send each write to the browser
                    System.Threading.Thread.Sleep(1000);
                }
            }
    
    ));
    
    //this will make sure that the response will stay open
    System.Threading.Tasks.Task.WaitAll(tasks.ToArray());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small web server for testing purposes using python, BasicHTTPServer and SimpleHTTPServer.
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
Declaring a class for (fast) testing purposes is great: require 'fast_helper' require 'site_search' class
When I use this code to download this image (only used for testing purposes),
I'm doing for testing purposes. I have this image: I encoded it to base
Friends, currently I dont have iphone to test and using Simulator for testing purposes.
I would like to create an in-memory database for testing purposes using Derby/JavaDB. I
I just tried the following code snippet for shellcode testing purposes:- #include<iostream> using namespace
I'm adding some attributes from live to staging for testing purposes, I'm using ldifde:
I need a mock implementation of a class - for testing purposes - and

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.