In my ASP.NET website, I am having a function which has to be automatically performed once every 2-3 mins on its own, i.e. without user intervention. This function contains database access.
Can I use threading to perform this process in background?
If Yes, How can I use that?
Edit
Also I am not looking for a solution which includes windows service because I am using shared hosting. So I dont have all the rights to access the host computer.
I have just started to look at the new "System.Threading.Tasks" goodness in .Net 4.0, and would like to know if there is any build in support for limiting the number of concurrent tasks that run at once, or if this should be manually handled.
E.G: If I need to call a calculation method 100 times, is there a way to set up 100 Tasks, but have only 5 execute simultaneously? The answer may just be to create 5 tasks, call Task.WaitAny, and create a new Task as each previous one finishes. I just want to make sure I am not missing a trick if there is a better way to do this.
This is my first forray into ASP.NET MVC, having been doing WebForms for nearly 6 years now. I've read through various tutorials and guides on getting started with MVC, but I've a few questions about how you're meant to do things:
UserControls for entities
In an application I wrote a few years ago (using WebForms) there were many entities that had an associated postal address (which existed as an instance of an Address class), so I created a UserControl that contained fields for working with addresses. During the page lifecycle I would pass the business object's .Address property to the UserControl for display and for population upon a successful and valid postback. How would I do something like this in MVC? My current project has a similar situation where common sets of fields are repeated throughout the application and all 'map' to the same class.
Modifying the page/view on 'postback'
Say I'm working on a data-entry form for an online B2B ordering system, where the user manually enters order items into a series of textboxes arranged in a table. The system can only provide so-many textboxes at a time (usually 5 or 10). If the user ran out of textboxes they would click an "Add more rows" button that performed a postback that was caught by that button's server-side .Click event handler. The page's class would then add more rows to the page; ASP.NET's stateful nature made this easy to implement. But in MVC there is no ViewState and I haven't found much information about how you'd do this, or anything like this. All of the tutorials and guides assume a form posting is only for data submission.
Multiple tasks per page/form
In a similar vein to the above, how do you create views that perform multiple tasks? In my above example I cited a webform that had two buttons: one to submit the form for actual processing, and another button that just modified the page (by adding more data-entry rows).Given that Controllers' actions are bound to URIs rather than what combination of fields were submitted, does this mean that I would have to interpret the posted data myself and branch based on that?
Finally, in many web applications you have the main form in the middle, but also things on the periphary of the page (e.g. a sidebar) that might have their own logic. For example, in one WebForms application I wrote last year there was a 'Quick contact' form in a UserControl located elsewhere on the page. When the user clicked the form's button the UserControl's logic handled the postback details independently of the page containing the UserControl (but there was only one <form> element in the whole rendered page). The user was returned to the page they clicked the button on, with everything in identical state as to how it was before, exccept for the UserControl which reported that the email was sent. Again, MVC's stateless nature would make something like this hard to implement, unless there are some techniques not covered in the tutorials?
MSDN says that MemoryCache's instance members are not thread safe. (http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(VS.100).aspx)
Does that mean every time I call Get() or Add() in a action method I have to wrap it with a lock?
I want to use my functions in DAL asynchronously by executing them in a separate thread. The issue in all this is suppose I have a function DAL.GetProducts() which returns a DataTable. If I execute this function in a separate thread, when it is completed how do I get the returned DataTable from this thread and bind it to my UI?
I'm trying to do some multi-threading in my asp.net web site. But I'm having trouble getting my child thread to interact with my main thread. In the following very simple example I would expect that, 3 seconds after clicking the button, the "Hello World" text would be displayed on my page and on my label. Instead, after a few seconds, I get the following error in a pop-up box "WebDev.WebServer20.exe has stopped working - Windows is checking for a solution to the problem.". I am running Visual Web Developer 2010 Express. If you know why I'm getting this error and if you know how to fix the problem respond.
I'm trying to get threading to work in ASP.NET but for some reason it keeps crashing my local server, and simply does not work at all when uploaded online. Here's the code:
protected void testThread() { for (int i = 0; i < 10; i++)
This may seem like a really simple question, but can I use the System.Threading namespace in ASP.NET web forms? I have a web page which uses HTTP GET/POST to gather page customisations (title, subtitle, etc.) from the user and numerical input which is passed to a ASMX web service. Currently they work sequentially, the customisation first followed by numerical processing. So can I use threading to do this?
I'm a completly noob in Multi-Threading c# web pages... and i'm taking the first steps... I have one web page that create one new thread for each image to load. Each thread only read the external image and save it to local server. I have for example pages that have 25 images... that page loads but it launchs 25 thread (1 for each image).
The code:
[Code]....
I assumed that when a thread finish it's job it will automaticaly be killed, is it that way ?? I'm asking because, when i try this code on the server, after some navegation and multiple images loaded the IIS goes down and the page return "Service Unavailable" error :( To solved it i need to restart the IIS Application Pool... For those that have experience in multi-threading web pages how can i kill this threads ? Aren't they suposed to be killed when their job is finish ? ? Do you know a good tutorial or article for begginers ???
I have a Main page containing links to five other pages. each page has a button which does some job using Thread. Problem is when i open a window from main page and click the button, The Process starts but if now i want to open another page from main window it doesn't load untill that previous page loads fully(when thread ends). I am not using any session variable on my page.
I m getting the error System.Threading.ThreadAbortException while exporting datatable to CSV. But export to CSV is completed sucessfully.Here is my Code:
I've got an asp.net application, it's running on DotNetNuke, under load we get the occasional out of memory exception. I've got a dump loaded it into windbg. the end of !dumpheap -stat is
I can't find much information on the System.Threading.ReaderWriterCount, as it seems to be the problem. What is the likely cause? Or failing that what's the best next step to work that out? Based on the pointer from the given answer I had a look at ReaderWriterLockSlim. I wasn't using it directly, but I saw that it had 88684 instances, digging deeper I saw quite a few classes with that number of instances, pointing to AutoMapper.MappingEngine. This should be a singleton, so I've had a look at where it's being created. I suspect that it's the DI container and have made some changes around that to see if it helps
I have a web app where a user will visit a page with a QueryString parameter passing the ID of the object I should retrieve.
What I then need to do is run a number of checks to ensure the user can access that data, and also find out if another user has a lock (recorded in the DB) on that object.
Currently these searches are all performed sequentially, however I'm thinking the best option might be to use delegates to be able to fire off the three or four searches required at once then use the results as they are returned.
My implementation for this would be using a delegate(s) and calling BeginInvoke, however I'm worried the overhead of threading this may lead to no speed increases.
My research has indicated it will use the ThreadPool, so there shouldn't be too much overhead, but I'd like to know if anyone has implemented this kind of solution to a similar scenario on a high traffic site and seen good resutls from it?
The reason I'm looking to do this is we are reengineering our application from the ground up, and need to make sure we are building something that will scale considerably.
I have a .NET 4.0 console application that does a lot of reads from SQL Server 2008 using the OleDbDataAdapter object.I tried to improve performance by spreading the processing logic across four threads using Visual Studio 2010's Task Parallel Library. Sadly the multi-threaded version is three times slower than the original. Using VS2010's performance tools, I found thousands of thread contentions caused by the method OleDbDataAdapter.Fill() which populates a DataSet.This is puzzling as there are no static classes or variables involved that would result in the OleDbDataAdapter being shared by my threads. Also, four simultaneous connections just can't cause a hold up at the database level, right? The default connection pool size should be much larger than this.
I have one button on my page. On click of this I need to run four methods parallely in four saperate thead and need to show the progress bar for each method. Also need to update the label controls form those threaded methods.
Also I need to user Update panel of AJAX control tool kit to avoid post back to user.
I have used the read pool for that. When I remove the update panel the code works fine and update four labels but when I put the update panel it is not updating the labels.
I am a beginner of C# programming. I have read a few books about C#.net. But I cannot find some exercises in the books. Someone told me to build up a blog to practice my coding.
But it is a huge task for a beginner. I just want some tasks to have a step by step learning process.
I used Castle Windsor before and had this routine that fired the certain method of all classes that implement a certain interface.If I recall correctly, the interface was IBootStrapTask and only had an excecute method. Then, for instance, I'd place all my route registrations in one of these, and know it get fired on application startup.Have to admit I did not understand the code to well, so I'm even more unsure how can I do this. I'm using structure map now. (still knowing very little about it)
When we talk about WebForms we say, for Administrative tasks, you must have an Admin folder to separate the admin task.
In MVC how i will treat my Admin tasks?
I will go for Admin Area or Admin Controllers,
Because if i will write controller for Admin tasks, each and every task will be written in one controller (AdminController) or if i will write Area -> Controller, means i will need to write at-least two controllers for each feature.
Second if we breaks the application in Areas (as modules) how i will manage Admin task for each Area.
We have a timer process (a JQuery plugin) that redirects after X number of minutes to the login page, all via JavaScript. When the timer hits zero, I want to run a task (could be anything; however, in this specific scenario, it's a web service call).
The issue I'm having is the web service that runs with the finish-up processes is not being called. The web service call happens, the redirect happens, I don't see any errors (I have try/catch statements around the setTimeout call), but no WS call.
As part of the web application I am working on there will be functionality to export data from the web application into a windows application copying the data between the database for the web application and the windows application. The databases for these two programs could have been combined but are being kept apart for simplicity.The utility to export the data can be triggered manually from the web application but it is also required that this task can be scheduled to run by the user (once a day, on web app shutdown etc)
I envisage this to be run as a service - I have created services for windows applications before but this is the first time I have needed to create this for a web application. Searching on goggle, I have found an msdn magazine article that suggests creating a web service and then creating a windows service which would call into this web service. So in my situation, I am thinking that I would create a web service which would contain the data transfer functionality between the web application and the windows application. Then I would create a windows service which would be installed as part of installing the web application, which would then call into the web service (at pre-defined intervals) using settings configured by the user within the web application (so that the data transfer functionality can be scheduled).Does this seem the correct solution? I would appreciate any advice on how I might achieve the above.