.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Threading for asynchronous activities

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net
 

I invoke a lot of asynchronous activities from my ASP.NET app. For example, when app starts, I put a file-system watcher on a folder and perform some actions when the watcher fires its events.

Also, I subscribe to Sql Server Query Notifications (manually, not using SqlDependency) and again actions are performed when notifications are fired.

I wonder which threads these asynchronus notifications are fired upon? Are they fired on an ASP.NET thread-pool thread, or another background thread?

Also, the notifications for Watcher and for QN would be fired on the same thread, or they would always be on different threads?

In these background threads, I create a custom HttpContext that is used by the code. Although I think this would be true, but I wanted to confirm that assigning HttpContext.Current is on a per-thread basis. So, assuming QN and watcher events are fired on different threads, and I assign a HttpContext to in both the events, is it guaranteed that the 2 HttpContexts would be different and the same code executing for the 2 events and accessing HttpContext would be accessing 2 different contexts??




View Complete Post


More Related Resource Links

Threading for asynchronous activities

  

I invoke a lot of asynchronous activities from my ASP.NET app. For example, when app starts, I put a file-system watcher on a folder and perform some actions when the watcher fires its events.

Also, I subscribe to Sql Server Query Notifications (manually, not using SqlDependency) and again actions are performed when notifications are fired.

I wonder which threads these asynchronus notifications are fired upon? Are they fired on an ASP.NET thread-pool thread, or another background thread?

Also, the notifications for Watcher and for QN would be fired on the same thread, or they would always be on different threads?


I always think tomorrow will have more time than today. And every today seems to pass-by faster than yesterday.
Rahul Singla | http://www.rahulsingla.com

Threading, Blocking, Events, and Asynchronous Management

  
Alright.

I think I have finally broken it down to what logistically could be explained for many who have trouble dealing with threads.  Naturally, of course, I don't have the answer, but I think I have the question.  Threading is always a mind boggle at times, but what is more difficult that the concept of threads is executing it in a specific framework.

There are multiple ways to handle Threading in .Net, and my questions revolve around them all, but with specificity as to the "How to code it" as opposed to "Explain the concept."

One method of threading:  The BeginXXX/EndXXX with IAsyncResult
Assumed Given:  When Calling BeginXXX(CallBack) the Callback is executed on a Secondary Thread.  Thus whatever code exists within the Callback procedure must either be self-contained, thread protected (with locks etc), and/or Synchronized if being communicated to other threads (namely the calling thread).

Another Method of Threading: Using the Thread class, and providing a TreadProc() callback method.
Assumed Given:  The ThreadProc() method is handled similarly to the Callback of the BeginXXX/EndXXX style of threading.  The difference between the two is that the BeginXXX/EndXXX style uses the ThreadPool to manage the thread, where with the Thread Class we (the programmers) are ma

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

  
Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

jQuery live() and ASP.NET Ajax asynchronous postback

  
The issue is that normally $(document).ready() is called when the DOM is ready to be manipulated. But this doens't happen after an ASP.NET Ajax asynch postback occurs.

This means that the initial jQuery bindings won't be automatically available after the asynchronous postback is over. I underline "automatically" here because my last post describes more possibilities, how this issue can be worked around.

Hello World to C# Threading Part 1

  
In this post we will see how we can implement simple threading. Why do we need threading? When you want you application to do more then one thing at same time, then you need to implement threading. One usual and common scenario would be when your application needs to get data from some other resource like web services and you don't want you application GUI to be freeze during this time. In that sort of case you will run the code to access web services in separate thread so your application GUI won't freeze. The System.Threading namespace .NET provide interfaces to implement multi threading.

Threading in C#

  
What is Threading?
-Parallel execution of code pieces on CPU, commonly compiled codes started in a single thread but it is possible to create multi-threads within a program.

THREADING IN C#

  
Multi-core processors are new standards on the user's hardware. By taking advantage of the multi-processing capabilities of these machines you can achieve significant performance upgrade with some minor changes in your code. When an application does not make use of threading techniques it is wasting valuable resources. This tutorial will cover the basic threading concepts and threading methods and properties.

Multi-threading in .NET: Introduction and suggestions

  
This article uses the C# type shorthands throughout - int for Int32 etc. I hope this makes it easier for C# developers to read, and won't impede any other developers too much. It also only talks about the C# ways of declaring variables to be volatile and locking monitors. Developers using other languages can find the equivalents in their own preferred environment, I'm sure.

Multiple Paramatized Threading issue

  

I need the funcitonality to have two methods run concurrently of each other and the parent thread (aka the method that makes these two calls) to halt until BOTH are done. After the threads are done, I need to perform logic on the returns of the method, so it is essential for both of them to be complete before the parent thread continues. I have searched the internet and tried varous attacks, and I always come up with the same result, this being the parent thread continues operation after the first thread finishes, leaving the second thread running.  Can someone show me a quick example of how I can do this. I have tried checking states of the threads, halting the threads, but I always end up with the same thing. Any help would be great. Thanks.


Cutting Edge: Revisiting Asynchronous ASP.NET Pages

  

If you need to scale up an existing Web application, you should first look to asynchronous operations, says Dino Esposito. He explains how new features coming in ASP.NET MVC 2 make this easier.

Dino Esposito

MSDN Magazine April 2010


Concurrent Affairs: Solving The Dining Philosophers Problem With Asynchronous Agents

  

We use the new Asynchronous Agents Library in Visual C++ 2010 to solve the classic Dining Philosophers concurrency problem.

Rick Molloy

MSDN Magazine June 2009


Foundations: Unit Testing Workflows And Activities

  

Matt Milner takes a look at some of the challenges and techniques related to testing Windows Workflow Foundation activities, workflows, and associated components.

Matt Milner

MSDN Magazine November 2008


Windows with C++: Asynchronous WinHTTP.

  

This month's column explains how to use Windows HTTP Services, or WinHTTP, the new, powerful API for implementing HTTP clients.

Kenny Kerr

MSDN Magazine August 2008


.NET Matters: Asynchronous I/O with WebClient

  

In this month's installment of .NET Matters, columnist Stephen Toub answers reader questions concerning asynchronous I/O .

Stephen Toub

MSDN Magazine July 2008


.NET Matters: Asynchronous Stream Processing

  

This month Stephen Toub discusses asynchronous stream processing.

Stephen Toub

MSDN Magazine March 2008


Concurrent Affairs: Asynchronous Device Operations

  

Jeff Richter uses the AsyncResult class to implement the CLR's Asynchronous Programming Model to perform hardware device operations asynchronously.

Jeffrey Richter

MSDN Magazine June 2007


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend