Results 1 to 10 of 10

Thread: How to handle multi user and client refresh

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    How to handle multi user and client refresh

    I've got a system where tasks get loaded and assigned to staff members.

    I'm thinking of how I would like to somehow refresh a client page for a staff member if a new task gets assigned to that staff member. Some clerical people will be loading and assigning tasks to staff members.

    How have you all handled this type of refresh in a webby environment. I'm fully jQuery and Ajax so I've got the tools...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: How to handle multi user and client refresh

    There is an MVC thingy I cannot recall right now that is like a messenger but we don't want to use that I guess(?).
    Can't recall the name.
    But how about a timer refresh on a web service to check for new data? As I haven't done anything similar this is how I would do I if there was no other solution.
    Seems logical with a simple 0-1 for new task
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to handle multi user and client refresh

    How often would you hit a service like that before it became overwhelming?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: How to handle multi user and client refresh

    Something like this would typically be achieved by long-polling.

    Something like this should work:

    Code:
    function checkForChanges(){
       setTimeout(function(){
          $.ajax({ 
    		url: "whatever", 
    		success: function(data){
            		//either refresh your page or modify the display
    			
            		checkForChanges(); //call the method again to ensure it is constantly polling
          		}, 
    		dataType: "json"
    	});
      }, 30000);
    })();
    This will recursively call the server every 30 seconds to check if anything has changed. If you're able to use HTML5 websockets or other technologies, there are also other, better, options available.

    This post goes into some detail about it.

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: How to handle multi user and client refresh

    Quote Originally Posted by szlamany View Post
    How often would you hit a service like that before it became overwhelming?
    We are talking about a 0-1 in a new data so, I don't know. How often can we hit a service with that request?
    I don't think it will ever become overwhelming but you are better in SQL than I am so I guess you can answer that yourself.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to handle multi user and client refresh

    I'm finally getting back to working on this...

    Lately I've been making use of the Application class - saving information in it during long running requests so that other requests can grab it.

    For instance - when a long running report starts in a web service - and while that request is still running - I can have the browser make AJAX hits back to the server to see how many pages are done.

    Class looks like this:

    Code:
        Public Class ApplicationMessage
            Private am_httpContext As System.Web.HttpContext
            Private am_sGuid As String
            Private am_appMsgType As String
            Private am_suppressMS As Integer = 0
            Private am_startTime As DateTime = Nothing
            Sub New(appMsgType As String, httpContext As System.Web.HttpContext, sGuid As String, initMessage As String)
                am_httpContext = httpContext
                am_sGuid = sGuid
                am_appMsgType = appMsgType
                am_startTime = Date.Now
                am_suppressMS = 0
                With am_httpContext.Application
                    .Lock()
                    .Add(am_appMsgType & ":" + am_sGuid, initMessage)
                    .UnLock()
                    Debug.Print(am_appMsgType & ": " & initMessage & " " & am_startTime.ToString())
                End With
            End Sub
            Public Function SendMessage(amMessage As String, Optional amOverride As Boolean = False) As Boolean
                Dim nowTime As DateTime = DateTime.Now
                Dim msDiff As TimeSpan = nowTime - am_startTime
                If Not amOverride AndAlso am_suppressMS > 0 AndAlso msDiff.TotalMilliseconds < am_suppressMS Then
                    Debug.Print(am_appMsgType & ": " & amMessage & " " & Date.Now.ToString() & "** suppressed")
                Else
                    With am_httpContext.Application
                        .Lock()
                        .Item(am_appMsgType & ":" + am_sGuid) = amMessage
                        Debug.Print(am_appMsgType & ": " & amMessage & " " & Date.Now.ToString())
                        .UnLock()
                    End With
                    am_startTime = nowTime
                End If
                Return True
            End Function
    Code:
    .
    .
    .
            Public Function SetSuppressMS(amSuppress As Integer) As Integer
                am_suppressMS = amSuppress
                Return am_suppressMS
            End Function
        End Class
    And it's called like this

    Code:
        Private _rptMsg As ApplicationMessage
    
        Sub New(httpContext As System.Web.HttpContext, sGuid As String)
            _httpContext = httpContext
            _sGuid = sGuid
            _rptMsg = New ApplicationMessage("acsReport", _httpContext, _sGuid, "Initiated")
        End Sub
    .
    .
    .
    _rptMsg.SendMessage("PrintReport:Started")
    .
    .
    .
    _rptMsg.SendMessage("PrintReport:Pages Completed: " + prtAddPage.ToString())
    _rptMsg.SetSuppressMS(1000)
    Then in another web method - one that is called every one or two seconds - I check this Application...Item and return it in a JSON string.

    Code:
                If ctrloption = "acscheck" Then
                    Dim strMessageText As String = ""
                    With Application
                        .Lock()
                        strMessageText = .Item("acsReport:" + sguid).ToString()
                        Debug.WriteLine(strMessageText & " " & Date.Now.ToString())
                        .UnLock()
                    End With
                    .NewObject("acscheck", True)
                    .Seperate()
                    .NewObject("messagetext", strMessageText)
                    .Seperate()
                    strMessage = "acsCheck Done"
                End If
    I just recently added that SetSuppress method so I can stop myself from filling this Application ITEM too frequently. I thought that could be a bad thing with lots of people hitting the server and running reports.

    I'm also using the Application...Item() list to store security facts about users logged into my web app.

    Now I'm thinking I can add more here - like the STATE of certain tables based on UPDATE's across the board.

    Am I getting too crazy with the use of the Application class? Anyone crash into limits here - scalability??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: How to handle multi user and client refresh

    Personally I haven't really used the application a lot. Not sure about locking and unlocking but I guess you know what you are doing.
    I am marking this down for more investigation when I have the time( currently super busy with the seat rules and stuff).
    But thanks you gave me something to think about.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: How to handle multi user and client refresh

    You should use SignalR, it is created for this kind of situation
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,605

    Re: How to handle multi user and client refresh

    I have suggested the same thing to szlamany in another thread but now I tend to disagree with my suggestion.
    After all SignalR is merely a copycat emulation of true JS web service calls.
    It's something (not quite of course) like an ol' updatepanel when you didn't quite got Jquery.
    And of course MVC (hate MVC).
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to handle multi user and client refresh

    Quote Originally Posted by Lightning View Post
    You should use SignalR, it is created for this kind of situation
    Why do you say SignalR - what does it give you??

    I've already got the Ajax/JavaScript part handled in the browser with other notifications I'm doing. That seems lightweight and probably as simple as I can keep it.

    The folllowing starts a report running and then does the initial call for a "check" of the results.
    Code:
    ctrlWebService("acsprint=" + rptSproc, ctrlval1, ctrlval2, ctrlval3, strCT, source);
    g_printCycle = 1000;
    setTimeout(function () {
        ctrlWebService("acscheck", "", "", "", strCT, []);
    }, g_printCycle);
    and when that ajax request completes it sets up another one - with a slowing increasing delay.
    Code:
    if (g_printOn) {
        if (g_printCycle < 3000) {
            g_printCycle += 500;
        }
        setTimeout(function () {
            ctrlWebService("acscheck", "", "", "", "", []);
        }, g_printCycle);
    } else {
        printMenuClear(sender);
    }
    Back on the server side I'm using the Application class to share information between different POST's and more importantly, make thread safe with .Lock()/.Unlock(). Not sure of the scalability here.

    I'm about to finish the code for this and get it into test with a user. I'll post back with my findings.

    Any other ideas/thoughts anyone can suggest - thanks!
    Last edited by szlamany; Nov 14th, 2015 at 01:32 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width