2

What is the best way to send messages to the user during a long process in asp.net. In other languages there is a flush method and I see that asp.net has that as well but is that the best way? If not, how else can you do this?

user204588
  • 1,613
  • 4
  • 31
  • 50
  • But while using thread in asp.net, we can not use session based information in the function being called from thread. –  May 15 '13 at 14:20

3 Answers3

2

The best way to do it is to spawn a separate thread that performs the long running process and then have an ajax call on the main thread that requests status from the long running thread and displays the status as appropriate.

A relatively good article that explains this in depth can be found here: http://www.devarchive.net/displaying_progress_bar_for_long_running_processes.aspx

moshjeier
  • 196
  • 6
0

As Adam Tuliper said -- you need a push notification framework, and the best choice would be SignalR from Microsoft. No need to store the status anywhere, or implement polling. SignalR will push everything you need back to the browser, while the request that started the process (on a different thread) sends its messages directly to the client via the HubContext class. The details can be found here.

ulu
  • 5,872
  • 4
  • 42
  • 51
0

Either use a push notification framework (comet) http://pokein.codeplex.com/ or save your status to a database and your page either refreshes to get the status or uses jQuery.ajax() for example to get the data back or refreshes an UpdatePanel on a timer such as: http://msdn.microsoft.com/en-us/library/cc295400.aspx

Either way though - your 'progress' needs to be saved to either the current session or to a database and read. The UI generally wouldn't interact directly with the processing thread, but both talk to some intermediate medium that contains the update status.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71