I'm quite new to asp.net and C# so bear with me. Also my apologies if this have been asked before... if so please direct me to a page which is of help.
What I have:
A page: With 4 updatepanels
1st UpdatePanel which contains a (item) gridview, user display options (not important to this question) and button which perform a database search which returns a list of items displayed to the grid. User selects an item on this grid...
2nd UpdatePanel contains a dropdownlist containing a list of available task loaded from an XML. User will select a task, which displays a bunch of available options/parameters (also loaded from XML file) to another (parameter) gridview in 2nd updatepanel. Gridview here will always have one row of data. I'm using gridview here because it is easier rather than creating dynamic controls (paramaters are different to each task ). User is able to enter parameter values into the grid. User clicks on an Add button and the the task is added to another gridview in the 3rd updatepanel.
3rd UpdatePanel contains a (task) gridview which contains all the task added by user. There's also a button which is suppose to batch run all the task. When the button is clicked, it goes through the (task) gridview looking for pending task to run. For each pending task, it calls a web service which handles the task appropriately. Web service returns the task result together with log output.
4th UpdatedPanel for now just contains a div that displays the log output returned from web service.
What I want to further work on and not know how is:
how do I perform an 'asynchronous' batch job? What i'm trying to achieve is that, when user clicks on the batch run button, the 3rd (task) updatepanel together with all it's control get disabled while the batch jobs run 'behind the scene'. Depending on the task, each task could take up to 5seconds each. If user had created 60 tasks, I would think this will also cause the page to timeout?
While the batch job is running, user can further search for other items in (item) UpdatePanel and add new tasks using (parameter) updatepanel to (task) updatepanel.
(Task) UpdatePanel will be showing a 'Job in progress...' overlay of some sort when job is running.
Hope you understand my question. Much appreciated if someone could be kind enough to give some guidance and/or directions on how to tackle this task
Further info:
Using Framework 3.5
Using Asp.net C# + Ajax
Web Service is of gSoap on a solaris box
Many thanks in advance.
Sorry for being a noob, i was trying to reply to your help but found that there's a limited of characters i can put in. I'll just update my own comments for now.
Thanks for your suggestion. Sorry for the late response, I've been looking around the other day and had made some changes, getting it to work with 'PageAsyncTask' and 'IAsyncResult'. I've created a web service class which will be called by the page. The new web service class will than called the gSoap web service. I've managed to some sort of running it 'asynchronously'.
I have a button which executes:
protected void StartASyncJob()
{
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginAsyncCommandTask),
new EndEventHandler(EndAsyncCommandTask),
new EndEventHandler(AsyncCommandTaskTimeOut), null);
RegisterAsyncTask(task);
}
BeginAsyncCommandTask will go through the grid, get the first pending task and calls the web service.
EndAsyncCommandTask will then retrieve the return results, writes out the (log) UpdatePanel. It will then execute StartASyncJob() again looking for the next pending record to process.
All this works ONLY if don't do anything else on the page.
If I was (while the asynchronous process was running ) to do a search for more items in (item) gridview or select a new task from
(task) dropdownlist, the event will not fire till the asynchronous web service process has completed. And when it's completed, the dropdownlist or search event fires, my log details returned from the web service is not updated.
I guess the 'wait' is caused by 'PageAsyncTask' being 'spawn' from the same page thread?
I would have thought having the 'asynchronous' web service will enable the user to do more than one thing at a time giving better user experience. But it seems I'm wrong and/or have not done it right.
I have not tried your suggestion of using QueueUserWorkItem; but before I do, may i ask if it will give the same effect as using 'PageAsyncTask'. Will using QueueUserWorkItem has the same effect of 'spawning from same page thread' ?
Many thanks in advance. Sorry if i've not explained myself well and please do let me know if you need me to post my code.
there are a few solutions, but depends on how much control you have on the server.
If you have full access control to server, you may create a separate application which will take care of the Tasks; the application can be a Windows Service, and the communication between your page and the application would be either a database or MSMMQ (the communication mainly means the list of the Tasks and their states - 1. to be executed, 2. executing 3. finished).
Another solution is in case you don't have full access control to server, but it will require to implement some communication between threads. Instead of having the application I described at point 1. you can have a separate thread, which can be started this way:
System.Threading.ThreadPool.QueueUserWorkItem(foo => LauchTaskRunner());
Suppose you implemented a method called LaunchTaskRunner which in a loop just processes the list of existing Tasks, the above line will start it into a separate process. You can communicate with this method (which is running in a separate thread) through some static variable (declared in the page), e.g.:
public class YourPage : System.Web.UI.Page{
static IList<Task> tasks;
static void LauchTaskRunner(){
// here make use of tasks variable
}
}
Everytime the (tasks)updatepanel gets refreshed, it should render based on tasks variable.
Related
Let's say I would like to change the text of an element, during some long function in a script:
// Inside test.aspx.cs
void SomeLongFunction_CalledOnClick()
{
this.idOfElement.Text = "something";
}
When, precisely, is the client sent information about this update? Can I force it to happen earlier?
If you are using web forms, the content of the browser is updated when the "Render" stage of the page life cycle runs. Generally the code in a web form's code behind runs before the render stage.
Here is a link that explains the page lifecycle
I'm afraid that if you are looking to update the UI to indicate progress, the web forms model isn't made to work that way. All the content is sent to the browser as a single unit during the render phase.
If you want your UI to show progress you could poll for updates using ajax calls, or use a technology like SignalR (although it's probably overkill for your use case).
I am not sure how should I put the title of my question, But I have one issue in Window based application C# code.
basically I am creating 2 WPF application in C#
For my First application, following steps are there
A. I am Creating some folders by C# code and showing status on a TextBox.
B. Then I am unzipping a folder by C# code and Copying files to a new folder location in C drive. This time also I have to show the status in TextBox.
But there is a problem with second step. Copying files blocked the first step to show the status in TextBox. I was hoping that It should show the status in TextBox first for the first step then it should start the coping files. Right now it shows the complete message in TextBox, after coping the files. :(
For my second application, I load XML with more then 3000 data in a List. So Loading and displaying the items in the list, block the entire application. So how could I resolve this?
I am new in .net, so please help me in that.
You need to use Threads or Background Workers to accomplish this task. When you do some work in single application, your UI will get block till some Long Task get completed [in your case updating your text box].
Also to access UI components not inside your own thread [Original thread] you will need Invokes. Go through guides and try to adapt techniques in them. In my experience "Background workers" are easy to work with.
Guides -
Backgorund workers
Invokes
Updating UI- in your case show progress
I am using a Radgrid in my page. There is a Refresh button in the page to refresh the page to see changes done by other users. I have so many functional buttons in the page (e.g.: mail sending, assigning a row etc…).During other processes if I click refresh button, will it affect the current processes? Is there any chance of data mix up?
It depends on your code.You have to handle each and every process safely,so that it may not mix up with other process.
If you are doing asynchronous calls, then you will have a very good chance of not mixing up data. The issue that might arise is that if you do this client-side via jQuery, then the async call might not make it back to the success/completed handler of the jQuery .ajax() function, especially if you navigate away from the page, but the server-side operation will continue its work.
You should send emails asynchronously when possible, using SmtpClient.SendAsync Method (MailMessage, Object).
How can I show some type of message in my ASPX web page ( I'm using WebForms, not MVC ), which represents as a "wait process" while some method of my project is executing.
I'm not asking about how to make some HTML/CSS/DOM stuff, I'm asking more about asynchronous check.
For e.g.: some data from web could be delivered to client not quickly and when it does occur - it looks very ugly for the user. It's just idling and looks like a page with bug, where there is no well highlighted status ( many users don't watch in browsers the page loading states, they want to look it in web applications exactly, like in desktop applications ).
I want to show a message like "waiting for the operation end"
and I don't know how to make an asynchronous check in my ASPX page for getting the current state when some methods execute ( are they finished or not etc... ).
What I really want looks like in pseudo-code:
while (methodExecuting) show(waitMessage);
How could it be done in WebForms of ASP.NET project?
I suggest you use a "progressBar" indicating your condition periodically.
Here is a good link explaining step by step how to use it.
Asynchronous processing in ASP.Net with Ajax progress bar
You can download this solution at the following: http://weblogs.asp.net/blogs/seanmcalinden/Solutions/AjaxProgressBarExample.zip
I would have done it with JQuery UI Progress Bar.
Change your C# function to webmethod and then call it with jquery. here is the tutorial for you. Call the webmethod and enable the progress bar, when it is completed disable the progress bar.
hope it helps.
I am fairly new to SharePoint 2010 Development. I have created a Task Tray Web Part to list all the tasks (from Workflow Tasks List) awaiting action by the currently logged in user. It is required that when the user clicks on a task on the web part, the associated Infopath form opens for action. I cannot retrieve the URL behind the "Title" Column of the Workflow Task List. Can you show me how to retrieve the URL behind the Title Column of a Workflow Task List in code? C#,VB.Net or JavaScript? Is there another way of achieving this? Thank you.
I kind of took my second advice/comment. I wrote a function that generates the required URL. Using this, I can now call any workflow list item. If I ever find a way to solve the original challenge, I'll be sure to post it here.