-1

I want to make a call to client side code - on the server side, I'm going to spin off n-threads to do work

When each thread completes I'd like them to each individually callback a client-side function in order to append the result to an HTML table

blue18hutthutt
  • 3,191
  • 5
  • 34
  • 57
  • 2
    you have 2 options: ajax polling or signalr – Cristi Pufu Sep 26 '13 at 16:55
  • possible duplicate of [calling a javascript function in C#](http://stackoverflow.com/questions/5445997/calling-a-javascript-function-in-c-sharp) – Geeky Guy Sep 26 '13 at 16:56
  • "I want to make a call to server side code" - What initiates this call, an AJAX request, or the browser requesting a URL? – mbeckish Sep 26 '13 at 16:57
  • An AJAX call will initiate the request from the client side – blue18hutthutt Sep 26 '13 at 17:01
  • @blue18hutthutt - Then the server should return the HTML snippet in the AJAX response, and the javascript that initiated the AJAX call should add the result to the HTML table. No need for the server to know anything about the HTML table. – mbeckish Sep 26 '13 at 17:06
  • @mbeckish - The problem with that approach is, if the server side code returns results at once like that, I won't get each update as the thread completes, rather I'm blocked until all threads complete, then returning the HTML back to the AJAX call that initiated it – blue18hutthutt Sep 26 '13 at 17:15
  • What's wrong with the AJAX call blocking until the server is done? The browser is still free to perform other actions. – mbeckish Sep 26 '13 at 17:27
  • Because I want to know as soon as a thread completes, when it completes. If a thread finishes in 2 seconds but the slowest thread takes 5min, I won't know until 5min later – blue18hutthutt Sep 26 '13 at 17:58
  • Instead of 1 AJAX call that kicks off N server threads, you could kick off N AJAX calls that each spawn 1 server thread, and each waits synchronously until the response comes back. – mbeckish Sep 26 '13 at 18:24
  • 1
    Why are you using threads? – Jason Whitehorn Sep 27 '13 at 14:13

1 Answers1

1

You have 2 options: ajax polling or signalr

Check this out: http://bsmadhu.wordpress.com/2012/04/30/real-time-web-using-signalr/

Cristi Pufu
  • 9,002
  • 3
  • 37
  • 43