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

  • Home
  • SEARCH
  • 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 607487
In Process

The Archive Base Latest Questions

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

My application is a LiveChat developed in C# and ASP.NET I have a Client

  • 0

My application is a LiveChat developed in C# and ASP.NET

I have a Client timer which call the webservice Function RetrieveMessages() every second.
Additionally, soon after the user send a message i’m call de same function RetrieveMessages().

I have a variable that store the last message Id, so, every RetrieveMessage call retrieve only the messages that is unread.

Sometimes the the client show the same message twice, like so:

Ewerton (14:22:20) : Hello!
Ewerton (14:22:20) : Hello!

the duplicity occurs only in client, the DataBase table is ok, no duplications.

I suspect tha the Timer, and the Send Message is executing a RetrieveMessage before the variable lastMessageId is updated.

How can i synchronize the call of the RetrieveMessage() ?

Here are some code to analise.

    // ThisFunction is a callback that RetrieveMessage every time the user send's a message
function SendMessageSucess(cdMsgEnviada) {
    //Carrega Mensagens
    Avalon.Services.ChatService.RetrieveMessages(CodChamado, IdLastMsg, RetrieveMessagesSucess);
}

OnTImer Tick

    // Every second, verify is exist new messages
function timer_onTick() {
    //Carrega Mensagens
    Avalon.Services.ChatService.RetrieveMessages(CodChamado, IdLastMsg, RetrieveMessagesSucess);
}

The RetrieveMessages function

function RetrieveMessagesSucess(result) {
    var myMsgs = new Array();
    for (var i = 0; i < result.length; i++) {
        var obj = eval('(' + result[i] + ')');
        if (obj != null)
            myMsgs[i] = obj;
    }

    for (var j = 0; j < myMsgs.length; j++) {
        if (myMsgs.length > 0) {
            // Armazeno o codigo da ultima mensagem recebida
            IdLastMsg = myMsgs[myMsgs.length - 1].cd_chat_message;

            if (par) {
                var novoconteudo = "<div style='background-color: #EFEFEF; padding: 10px;'>"
                par = false;
            }
            else {
                var novoconteudo = "<div style='padding: 10px;'>"
                par = true;
            }

            if (myMsgs[j].origem_mensagem == 1) // Msg enviada pelo cliente
                novoconteudo = novoconteudo + "<b>" + myMsgs[j].solicitante + ": </b>"
            else
                novoconteudo = novoconteudo + "<b>" + myMsgs[j].tecnico + ": </b>"

            var objDate = eval(myMsgs[j].datahora.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));

            novoconteudo = novoconteudo + "(" + objDate.format("HH:MM:ss") + ") ";

            novoconteudo = novoconteudo + myMsgs[j].texto + "</div>";

            divChatHistory.append(novoconteudo);

            AutoScroll();

            if (myMsgs[j].origem_mensagem == 2) // Msg enviada por um tecnico
                show_popAlert()
        }
    }
    // Verifico se o chat esta ativo
    IsChatInativo();
}

Any Ideas ?

  • 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-13T17:21:55+00:00Added an answer on May 13, 2026 at 5:21 pm

    Set a global variable that is an object and create a new property in it whenever you add a new message to the conversation. Use your message ID in the name of the new property and set it to true or something. If each of your messages has a unique ID, then you can just verify that you haven’t already processed that message before proceeding by checking for the existence of that message ID’s specific property in your object.

    Might look something like:

    var PROCESSED_MSGS = new Object();
    

    and then later…

    for (var j = 0; j < myMsgs.length; j++) {
        if (myMsgs.length > 0) {
            thisMsgId = myMsgs[j].id;
            if(PROCESSED_MSGS['msg'+thisMsgId]) continue;
            PROCESSED_MSGS['msg'+thisMsgId] = true;
            //keep going....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Application frameworks such as DotNetNuke, Eclipse, Websphere and so forth are available today which
Application : I am working on one mid-large size application which will be used
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Application uses Entity Framework 4.1 with database first approach. I have in database a
application design/architecture question for a project that I am building. I have a main
Application.Run(form); Actually I tried to call this from my project. I got this exception.
I am trying to create a ZF application that also includes Mibew Messenger which
Application is a C# .Net 3.5 WCF Service. I'd like during the build process
APPLICATION and ENVIRONMENT Java EE / JSF2.0 / JPA enterprise application, which contains a
I have a web application that requires Blog Forum Chat support etc Now my

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.