C# - How To Run Long Running Operation Asynchronously And Show Loading For The User In Ajax And Poll For The Result
Mar 24, 2011
heavy operation which takes long time to be completed in my asp.net application. I don't want to run the entire operation in one request which may result in a TimeOut error. Instead I want to invoke the operation in a separate thread and poll for the result every x seconds. How can I do this?If the operation gets completed I need to register a script in the ajax postback to hide the loading panel and show the content. However I'm not able to register new scripts and invoke it during ajax postbacks.
in my case, It is the windows service which in running the long running insert/update on a table and I need to cancel the operation from my ASP.NET application. In the above link Burnsys suggests that one should kill the Sql server session. Is that really only way and a goood practice to do this? Also, in the same poset can use SqlCommand.Cancel to cancel. However, I am not sure how can I cancel the command from the windows service from ASP.NET application.
Note:- i don't want to use updateprogress etc. control of ajax
When testing this locally (on my dev machine) i see the application is working alot slower.
Is there a better way to write this code? Should i use ThreadPool.QueueUserWorkItem or create a new thread using Thread t = new Thread(new ThreadStart(DoWork)); ? Will it be better to create a totally seperate application for the purpose of sending the newsletters. will that help if ill run this application on the same machine?
i've seen other posts here talking about ThreadPool vs Thread but its seem no one is sure which is better.
When an ASPX page needs to make a call to a potentially long-running operation (lengthy DB query, call to a remote webservice, etc.), I use RegisterAsyncTask, so the IIS worker thread is returned to the pool, rather than being tied up for the duration of the long-running operation. However ASMX webservices don't have a RegisterAsyncTask function. When an ASMX webservice needs to call a potentially long-running operation, how can I implement the same behavior as RegisterAsyncTask? Note: the ASMX webservice is implemented as a script-service: returning json to a direct jQuery/ajax call. Therefore, I cannot use the "BeginXXX" approach described by MSDN, since that implements the asynchronous behavior within the generated client-stub (which isn't used when calling the webservice directly via ajax). EDIT: Adding source code: implemented the BeginXXX/EndXXX approach listed in John's answer. The synchronous "Parrot" function works fine. But the asynchronous "SlowParrot" function gives an internal server error: "Unknown web method SlowParrot"
I've been having a difficult time with this. I have an asp.net page. The user hits the "Run" button and I have code IN AN ASSEMBLY, not in the APP_CODE folder that is called and runs a long process that moves product info from a file into the database. While the user waits, I would like them to see status updates like what product the import process in on and status info. I'm assuming I'd break off into another thread and use Ajax but I have no idea how to do this.
I wrote a test page that does a bunch of busy work in a method called at page load. This process as I have it now takes around 12 seconds.
If I try to load another page while the first long running page is loading, this second page doing nothing except writing out a world, it doesn't load until the first long running page is finished.
Why is this the case? I would think IIS would be able to handle multiple concurrent connections, it seems crazy that one long running page would stop every other page in the application from loading. I must be missing something or not understand how IIS works.
I would think multiple independent requests would be spawned on different threads. Is this only the case if the requests are from different sessions entirely? Are all requests from a single session bound to a single thread?
Frameworks like Node.js, Tornado, and Twisted let developers create server-push applications that supports large number of concurrent hanging requests (10k+). From what I understand, they all achieve this by not creating threads to service each hanging request.
Can AsyncController be used to service large number of inactive concurrent requests?If so, are there any reasonably large ASP.NET MVC websites using this approach to create long-poll applications?
I've developed a web application to accept video file uploads and then pass them to a backend service on an external server. The application runs without error on the visual studio debugging webserver, but once on a production iis 6 or 7 server, yields a timeout error at about a consistent amount of time into handling a large upload. Specifically, it errors in the middle of transferring the video file to the external server, once the application has successfully received it from the client. I'm aware of several timeouts to be configured related to the problem, and have done so. The application's web config has been tested with one or both of the following settings
<system.web> <httpRuntime executionTimeout="9999999" maxRequestLength="2048000" /> </system.web> and <configuration> <location path="default.aspx"> (the page at issue that's timing out) <system.web> <httpRuntime executionTimeout="9999999" maxRequestLength="2048000" /> </system.web> </location> </configuration>
And within the initialization of the webrequest made to the external server to send the video received from the client browser:
So with the execution time limits on both the webform as a whole and the connection made to the external server, I'm at a loss for what timeout is left unconfigured, or how to determine such, when I continue to get the following error: Unexpected error executing Brightcove Upload:...........................
I have a long-running WCF service that I need to call, but I would like to do is to open modal window (modal popup extender) that simply shows progress and stops the user from interacting on the page until the service returns. What I was trying to do was the following:
1. Click button to activate the process which calls a method in my code-behind. 2. This method opens my modal panel with some pretty animation. 3. I call my WCF service asychronously so that the UI will refresh. 4. Service ends which calls my delegate I setup. 5. My delegate method would then refresh the page with results, and dismiss the model popup.
I need to invoke a long running task from an ASP.NET page, and allow the user to view the tasks progress as it executes.
In my current case I want to import data from a series of data files into a database, but this involves a fair amount of processing. I would like the user to see how far through the files the task is, and any problems encountered along the way.
Due to limited processing resources I would like to queue the requests for this service.
I have recently looked at Windows Workflow and wondered if it might offer a solution?
I am thinking of a solution that might look like:
ASP.NET AJAX page -> WCF Service -> MSMQ -> Workflow Service *or* Windows Service
I am executing a long-running Oracle stored procedure from .NET. The procedure takes about three hours to run. Ideally, the user should be able to kick off the procedure, close the browser, and come back later to check the results.
The problem is that the connection to the Oracle procedure is lost after exactly an hour. As you would expect, the Oracle procedre runs to completion if it is executed from SQL Plus. Strangely enough, it will also run to completion if I run in debug mode on my local machine (I start two threads, one of which executes the procedure. I set a breakpoint on the second thread).
Here is my connection string:
data source= (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=serverx)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=TestSID)))
I am experiencing a request timeout from IIS when I run a long operation. Behind the scene my ASP.NET application is processing data, but the number of records being processed is great, and thus the operation is taking a long time.
However, I think IIS times out the session. Is this a problem with IIS or ASP.NET session?
What are the alternatives to System.Diagnostics API for running external EXE or BAT files under IIS hosted web application?
I would like to run external EXE program from my ASP.NET-MVC web application. I don't need to wait till the program exits. I just want to start the program. The execution can take some time or it may crash, so I would like to run it separatelly from IIS in such a way that the web application only triggers its execution.
I need to run the HttpContext.Current.Server.Execute method in my ASP.NET application. This application has a WCF operation that does some processing. Currently, I am running a Server.Execute call from within my WCF operation and getting the results I would expect. However, I would like to do this asynchronously.This is where my problem comes in. In an error to run Server.Execute asynchronously, I tried running Server.Execute in the DoWork event handler of a BackgroundWorker. Unfortunately, this throws an error that says
"object reference not set to an instance of an object"
The HttpContext element is not null. I checked that. It is some property nested in the HttpContext object that appears to be null. However, I have not been able to identify why this won't work. It happens as soon as I move the processing to the BackgroundWorker thread. My question is, how can I asynchronously execute the Server.Execute method? Are there options beyond BackgroundWorker that will work?
I have a view.On which i have two partial viewMy m ain is like this ->.(Note i am using Ajax.BeginForm here.)
butmy issue is this that i have a button in SearchRequestCriteria partial view on which a function from my controller is called.And the result is bind into the SearchRequestResults partial view.but from when i am using Ajax,BeginForm is does not bind the result to thisSearchRequestResults Partial view.I have debug the program & found that the result is came into the SearchRequestModel & but it does shows in the SearchRequestResults partial view.i want the result in this by using Ajax.
I have a datasource (which is a query) that could run more than 30 secs. I want to show to a user an animated icon (I have it already) while the Gridview is waiting to return data.
I studied several tutorials and textbooks but all just "thoerectically" use a timer to simulate, without much application to real example above. How should I code it in the above real scenario ? In which event handler to put the code and what control (Update panel) to use and any sample code ?
I have an accordin in my asp.net page, users can upload document and images,and I save the image and document path on sql server,and get the information from there,to show the document and image which are saved in web server,
How can I show loading image, or progress bar, when the user first connect to the web server?
I am using ASP.NET and SQL Server. I would like to load data from database asynchronously and show data which are partially loaded immediately.Suppose there are tons of records in a query result. After 3 sec,It loads 20% then I have to process and show 20% data immediately, not waiting for complete response. I know $.Ajax in jQuery to load data async. Is it possible to process partial response, Not wait for complete response and show it immediately.
In an asp.net web form, I keep getting a connection reset error message. The page is doing a some long running processing (about 2-5 minutes).
I have no problem when the web request comes from the same machine as the web server. But when the request originates across the network, I get a connection reset error about 1:30 or 2 minutes into waiting for a response.
I have set the in web.config for this application and put the application it's own application pool.
What else can I try?
The purpose of this page is to accept input from the user, calculate something, and send the result back to them. The long running calculation isn't something I can offload until a later time.
I am using a master page which has a table that is used for layout. In one of the cells I have a Accordion control which holds links in each panel to navigate to the various pages. I have a few pages that take some time to load so I was trying to use the update panel progress control, however it seems that you cannot use a hyperlink or a link button as triggers for the update panel or if you can you cannot if it is in an accordion control.
So I am seeking advice on how to show a loading message when the pages load in the content panes.