Multithreading - Want To Create A Thread In A Mvc Application?

Nov 5, 2010

I want to create a thread in a asp.net mvc application. What will happen?

A) Thread will die when request ends and the response is sent.

B) Thread will continue to run and response will be sent when thread terminates.

C) Thread will run without blocking the response and die when it have completed it's task

View 1 Replies


Similar Messages:

C# -.NET Multithreading & "thread Has Already Entered The Lock"

Feb 9, 2010

In an ASP.NET application, I have a resource that is protected by a ReaderWriterLockSlim.

Normal requests call EnterReadLock, access the resource, call ExitReadLock and return.

At one moment, I accidently forgot to put a call to ExitReadLock somewhere in my code. On the next request, I got an exception stating that the thread had already entered the lock.

Fair enough: if at the end of request A the thread does not exit the lock, and that same thread is used to process request B, and tries to enter the lock, it will throw.

Now, my question: is the following scenario possible? reasons?

thread begins to process request A
thread enters lock
thread does, say, sleep, or do some IO, and so becomes available same thread begins to process request B, while request A is "on hold"
thread enters lock !! throws !!


If yes, what other solution do I have to protect said resource? Bearing in mind I want to use a ReaderWriterLockSlim because I also have other thread that may write to the resource?

edit: add some details: 1) This happens in the ProcessRequest method of an HttpHandler which generates, caches and serves images. These images are expensive to generate. So, the first request will generate and cache the image, and we want to put the other requests on hold while generating.

2) We have not tried to "reproduce" -- at the moment we're trying to know if it is possible or not that the same thread begins processing a request while already waiting for the image to become ready.

3) I am aware of the LockPolicyRecursion but I am not sure I fully understand its purpose, and whether it would be OK to set it to SupportsRecursion in our case.

edit: going further...According to the document pointed to by Ryan below, a thread will block and not return to the pool as long as we don't engage into async operations. So once we've locked the thread waiting for EnterReadLock to complete, it won't return to the pool nor process any other request.

So 1) we should be safe but 2) we might starve the thread pool. Assuming we don't want to immediately return a dummy "please wait" image, what solutions do we have?

View 2 Replies

Create A 'thread' To Execute A Function On Page Load / Application Start?

Jan 10, 2011

I need to call a function everytime a visitor visits one of my website's page. But I do not want the execution of the function to interfere with the interface between the user and the website i.e. different thread. What is the best way to do that on ASP.Net?

View 3 Replies

Web Forms :: Implement Multithreading Into The Web Application?

Aug 27, 2010

i want to impliment multithreading into my web application how to do that..

i have already knew the concept of multithreading but want to impliment into application..

i have developped an application this application runs correctly for 400 users but when more user hits the server than the application fails to respond...

how improve the performance of the application..is this problem is related to the database server of the application server.

View 1 Replies

Cross-thread Operation Not Valid: Accessed From A Thread Other Than The Thread It Was Created On

Apr 2, 2010

I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-

Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.

i have tried invoke required but again got the same error. Sample code is below:

[code]....

View 1 Replies

Application Domain Vs Thread - Relationship?

Mar 29, 2010

Can someone explain me what is is the relationship between App Domain and thread? msdn says "threads are free to cross application domain boundaries; a new thread is not created for each application domain." suppose there is one thread t inside Appdomain a1 .there is an another App domain a2 .thread t can cross to a2 from a1 means it can access a2 memory area If thread can cross the app domain boundaries share the memory space then how application domain isolation is still there?

View 5 Replies

C# - Continuously Running Thread In Web Application?

Mar 31, 2011

i want a continously running thread in my web application for sending mail to admin if the logged complaint of the user in not solved by technician within 24 hours.

i am able to send mail to administrator

i just want a watch on database for unsolved issues with timespan of more than 24 hours and inform to administrator about the same

View 3 Replies

Web Forms :: Create Worker Thread In Webpage?

Feb 5, 2010

I am developing an asp.net application which provide a UI for user to submit some kind of job.

Behind the scene, i created a thread to sleep around certain mintues and then process the submmitted job. I would like to ask this is right way to create some worker threads to process the jobs? any risk in threading? any other alternative?

currently, i am facing the timeout of asp.net session. For example, the period of sleeping is 25 mins, the thread will not be processed because the asp.net session is timeout in 20 mins.

View 2 Replies

C# - Load Data To Application Domain Using A Thread?

Jan 22, 2011

I want to load data to my application domain using a thread so it will be executed at all times. How can I achieve this? I want the thread will start when iis starts and terminate when iis exits.

Note:

I want to do this so I can use disconnected architecture in my asp.net application.

View 1 Replies

C# - Async Function Thread.Sleep In Web Application?

Sep 8, 2010

I maintain a ASP.NET web application that causes a user's network connection to reset for several seconds when it executes a procedure. Therefore, the page request times out on the user's end as they never receive the web application's response (the connection dies before it gets the response packet).

To resolve this situation, I was contemplating having the ASP.NET page execute an asynchronous function that incorporates a Thread.Sleep(5000); // sleep for 5 seconds before executing the connection reset This way, the browser has 5 seconds to receive the page's response before their connection resets.

I have concerns with using Thread.Sleep and asynchronous functions in ASP.NET though. I've never attempted to do it before, so I'm unsure of the potential problems it may cause. Does anyone see potential problems with starting an asynchronous thread that contains a Thread.Sleep in an ASP.NET application?

View 3 Replies

MVC :: Identity.Name Is Disposed In IIS7 Application Thread?

Jun 16, 2010

I don't know if it's IIS, ASP.NET or IIS7 related. I take a chance here, if you think I'm in the wrong forum, just tell me which one I should post to.

I have made the smallest demo project to illustrate my problem. You can download the sources

Here

Visual Studio 2008, .NET 3.5, IIS7, Windows 7 Ultimate 32 bits. The IIS Website is configured
ONLY for Windows Authentication in an Integreated pipeline app pool (DefaultAppPool).

Here's the problem. I have an Asp.NET MVC 2 application. In an action, I start a thread. The View returns.

The thread is doing it's job... but it needs to access Thread.CurrentPrincipal.Identity.Name

BANG

The worker process of IIS7 stops. I have a window that says: "Visual Studio Just-In-Time Debugger An unhandled exception ('System.Object.DisposedException') occured in w3wp.exe [5524]"

I checked with the debugger and the Thread.CurrentPrincipal.Identity is valid, but the Name property is disposed.

If I put a long wait in the action before it returns the view, then the Thread can do it's job and the Identity.Name is not disposed. So I think the Name gets disposed when the view is returned.

For the sake of the discussion, here's the code that the thread runs (but you can also download the demo project. The link is on top of this post):

[Code]....

Here's the code that starts the thread

[Code]....

View 3 Replies

Visual Studio :: Debug A Multi Thread Program To See Local Variables Of Each Thread Using 2008

Jan 27, 2010

How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.

View 1 Replies

Architecture :: How Can Thread Update A Variable Shared With The Main Thread

Nov 24, 2010

I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.

Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.

Here is a quick example of how I use threading:

[code].....

View 3 Replies

How To Start A New Thread To Query A Database While Web Application Continues Running

Feb 11, 2011

I want to start a new thread to query a database while my web application continues running. I was under the impression that by using threads I can run the querying process independently while the normal web application page cycle carries on, but I could be wrong.

public class DbAsyncQuery
{
Dictionary<string, object> serviceResults = new Dictionary<string, object>();
public void UpdateBillingDB()
{
QueryAllServices();
foreach (KeyValuePair<string, object> p in serviceResults)
{
IEnumerable results = (IEnumerable)p.Value;
IEnumerable<object> sessions = results.Cast<object>();
DbUtil.MakeBillingDBEntry(sessions, p.Key);
}
}
public static string[] servicesToQuery = new string[] // Must go in config file ultimately
{
"xxx.x.xxx.xx"
};
public delegate void Worker();
private Thread worker;
public void InitializeThread(Worker wrk)
{
worker = new Thread(new ThreadStart(wrk));
worker.Start();
}
public void InitializeQuery()
{
Worker worker = QueryAllServices;
InitializeThread(worker);
}
private void QueryAllServices()
{
Dictionary<string, DateTime> lastEntries = DbUtil.GetLastEntries();
foreach (string ip in servicesToQuery)
{
string fullServicePath =
"http://" + ip + ":800/MyWebService.asmx";
//object[] lastEntry = new object[] { lastEntries[ip] };
object[] lastEntry = new object[] { new DateTime(2011, 1, 1, 0, 0, 0) };
object obj = WebServiceHandler.CallWebService
(fullServicePath, "MyWebService", "GetBillingDBEntries", lastEntry);
serviceResults.Add(ip, obj);
}
}
}

It seems to basically stall and wait to finish the query before loading the page (which can be thousands of rows, so it takes awhile). I put this in the following section of Global.asax:

protected void Application_Start(object sender, EventArgs e)
{
DbAsyncQuery query = new DbAsyncQuery();
query.UpdateBillingDB();
}

This is one of my first web pages, and I'm new to threading. I understand there is a difference between creating your own thread and using the ThreadPool. In this method, I am using my own thread, I think. Not sure if that's the best way. The querying process can be completely independent, and its only going to occur on scheduled intervals (every 8 hours or so). The user doesn't need to have up to the minute data, so it can take awhile. I just don't want the site to wait for it to finish, if that's possible.

View 1 Replies

Data Controls :: ProgressBar Thread With Database In Windows Forms Application

May 22, 2013

How to use progressBar with thread in windowsApplication..

I have a for loop in c# layer when loop start progressBar with start and  when loop finish progressBar is full ???

View 1 Replies

What Are The Differences Between Currently Executing .NET Thread And Win32 Thread

Mar 24, 2010

I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.

# WindowsIdentity = WindowsIdentity.GetCurrent()

which returns the identity of the security context of the currently executing Win32 thread.

# Thread = Thread.CurrentPrincipal

which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.

View 1 Replies

C# - Lock Thread.sleep Not Working With .NET Thread?

Jun 25, 2010

I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having

bool isGoodPassword = (password == expected_password);

lock (this)
{
if (!isGoodPassword)
Thread.Sleep(2000);
}
I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.

View 4 Replies

Web Forms :: Use Thread.sleep Method For A Particular Thread?

Aug 27, 2010

I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.

View 5 Replies

C# - How To Create Threads In Webpages From CLR Thread Pool Instead Of Pool

Oct 24, 2010

If I create a new thread on an ASP.NET page the IsThreadPoolThread property is true.

First question is, is it from ASP.NET pool or CLR pool ?

Second question is, if it is from ASP.NET pool then how to create a thread from CLR and don't use ASP.NET pool ?

View 3 Replies

Vb.net - .net Multithreading With Synclock?

Jan 31, 2011

i have some test code which i run at every load of a page in my asp.net website

this is the code

Sub TryThreads()
Dim t1 = New Thread(AddressOf TryLock)
t1.Priority = ThreadPriority.Lowest[code]...

the "dotrace" simply add a record to a log table in the db.now the right result would be that i should have the entries in the db in order "entered","exiting","exited"but actually when i look in the db i see first 2 "entered" then 2 "exiting" etc.meaning that the multithreading is working ok, but not the synclock is that correct?the real code will be adding records to the db and might be called from several pages of different sessions, but the same code must not run twice concurrently.

EDIT:in response to Sashas wonderful post i changed my code to a class (it was in a module) and now it looks like this:

Public Class CheckClass
Property LockObject As Object
Get [code]...

if i open multiple pages at once, they still clash some times. but if i'm correct, the issue is now not with the synclock as much as with the httpruntime.cache, because when using a standard property, on one page, the code works 100%. so how can i make sure that 2 threads, even from totally different sessions never run the trylock simultaneously?

View 1 Replies

Multithreading As A Web Method?

Feb 3, 2010

I'm working on my project, I want to ask is it possible to create multithreading in the web method at the web server side instead, not the client side.

View 3 Replies

How To Ensure Background Thread Ends When Application Ends?

Aug 12, 2010

I have an asp.net application with a background thread. The thread starts when the application starts and it is gracefully stopped when the application ends. I am running the website on a shared host. Unfortunately sometimes the application does not trigger the Application_End event when it ends. I would think that the threads would be killed anyway, but that's not the case. I currently have 4 threads running in the background. Three from previous times the application started and 1 from the current application session. How can I ensure that the threads are shutdown when the application ends? Is there a way for the threads to check if the application was reset or had been reset? Or is there a way to check for these rogue threads at application startup and kill them?

View 1 Replies

Multithreading Accepts Value And Return Value?

Dec 18, 2010

I wrote the following code to return a pdf report. The code is based on a multi-threading sample code. Can you guys provide some feedback about it, I am new to mulit-thread.

public delegate void StreamResultDelegate(Stream streamResults);

public class GenerateReport
{[code].....

View 2 Replies

Multithreading In Dotnet Apps?

Sep 30, 2010

Multithreading in dotnet apps?

View 3 Replies

Web Forms :: Implement MultiThreading In Web Applications?

May 7, 2015

i want know how i can insert data to database in background process

like when you like or unlike a post in facebook

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved