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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:43:48+00:00 2026-06-11T02:43:48+00:00

During create a chat system , I use a long life request to get

  • 0

During create a chat system , I use a long life request to get message , and use a jquery request to send message like this :

*Send: *

$("#btn").click(function () { 
    $.ajax({
        type: "POST",
        url: "Chat.aspx/Insert",
        data: "{ 'Str' :'" + $("#txtStr").val() + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
        },
        error: function () {

        }
    });
});

Receive :

function Refresh() {

    $.ajax({
        type: "POST",
        url: "Chat.aspx/GetRecords",
        data: "{ 'Id' : " + $("#hdnV1").val() + "}",
        success: function (data) {

            $.each($(data.d), function () {

               //Show it to user

            });

        },
        complete: function () {
            return Refresh();
        },

        contentType: "application/json; charset=utf-8",
        dataType: "json",
        traditional: true,
        async: true
    });

}

and this is my server side code to get messages :

[WebMethod]
public static object GetRecords(int Id)
{
    TestEntities db = new TestEntities();
    int count = 0;
    while (true)
    {
        if (count++ >= 300)
            return null;


        System.Threading.Thread.Sleep(1000);
        var list = db.Commets.Where(rec => rec.Id > Id).Select(rec => new { Id = rec.Id, Str = rec.Str }).ToList();

        if (list.Count > 0)
            return list;

    }
}

When user writes something and clicks on the Send button , request goes to pending state , and I thing because the long life request is executing

I check them up in firebug, is there anybody out there to help me !?!
For more details comment me please , and sorry about my bad English syntax , I am new in English

Thanks

  • 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-11T02:43:49+00:00Added an answer on June 11, 2026 at 2:43 am

    This is not the best method to build a chat in asp.net. As the number of users increases this method won’t scale.

    Take a look at SignalR is a good option to build a chat application.

    However if you do want to do it yourself for some reason, the most efficient method to build a chat in asp.net is to use a IHttpAsyncHandler and ajax requests.

    Asp.net has a limited number of worker threads. Putting one of them to sleep will just kill your application even for a relatively small number of users.

    An async request allows you to delay the response of a request till an external event occurs.
    A user makes a call to this handler and waits till someone sends him a message.
    Messages are delivered as soon as you send them to a user.

    On receiving a message the client makes another request and waits for the next message.
    This is how you keep a persistent connection open and allows the server to push data to the client.

    This is a lot more efficient than polling the site to check if messages have arrived.
    Using the async handler also ensures that no asp.net threads are wasted while a user waits for messages to come. Polling with a timer you will quickly run out of threads to process requests in asp.net.

    This ensures that your chat can scale well even as the number of users of the site goes up.

    Here is a completely working project that implements this, along with ajax.

    Avoid using a database as the method of communication between users on your site. If you want to log the chats, make all the writes async calls.

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

Sidebar

Related Questions

I used this tutorial to create a basic Javascript function for implementing change during
I'm building a system which can create forms during runtime. System is written for
I'm attempting to use Wix to create a database during install. I have my
using rails with Paperclip, I can use the following to get the filename during
i get an Exception during (UIElement)XamlReader.Load(...) which says 'Cannot create unknown type 'TextBox'.' Line
I would like to find a way to create and populate a database during
i'd like to create loading screen during executing funcion - something like loading screen
How do we create multiple thread during runtime in C programming language? If we
During the installation of my app, I want to create a PostgreSQL-Database and some
Is the option to create a desktop shortcut during installation only available if the

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.