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


Post New Web Links

Threading, Blocking, Events, and Asynchronous Management

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :.NET Framework
 
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


View Complete Post


More Related Resource Links

Windows Management Instrumentation: Create WMI Providers to Notify Applications of System Events

  

Windows Management Instrumentation (WMI) is based on an industry-wide standard for notifications used to manage objects and devices across a network. By receiving WMI events, an application can be notified of changes to data in WMI itself. This allows the developer to notify the consuming application that certain system configuration data has changed, without the application having to poll WMI continuously for this data. The author presents an explanation of the different types of events in WMI, then goes on to develop an event provider.

J. Andrew Schafer

MSDN Magazine September 2001


Asynchronous WCF call seems to be blocking

  
Hi all,I have a Silverlight application that calls a WCF web service which is hosted in an ASP.NET web application. On the client side I call two methods A and B on the service's interface asynchronously; each time a new proxy is created and used to call the respective method. Since the service has its InstanceContextMode set to PerCall, each call should create a new service instance and be independent from the others.For testing purposes I have added a Thread.Sleep(5000) to the implementation of method A.What I expect now is that when the client calls methods A and B one after the other, the service should process both calls in parallel and since method A has the call to Sleep(), method B should return first. Five seconds after that, method A should return as well.For the very first attempt in the web application's lifetime this works as expected, i.e. after rebuilding or performing an iisreset and calling those methods from the client side, it shows the expected behavior explained above. Here's a sample debug dump I received on the client:    Method B, 17:41:23, Server-Thread-ID: 9    Method A, 17:41:28, Server-Thread-ID: 8But after that, when I call those methods again (in exactly the same way), method A seems to block on the server:    Method A, 17:42:43, Server-Thread-ID: 1    Method B, 17:42:44, Serv

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?

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??


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

Active X events and threading

  

I have an application that exposes a dll to be used as an Active X control so I can control my application from JavaScript inside a webpage. I followed basically this example: http://www.codeproject.com/KB/cs/cs_com_obj_for_javascript.aspx?msg=3664764#xx3664764xx

Now I'm having a problem with handling the event and I think it is because of the way it's threaded. In my Active X control I have an event of type Action (i.e. no arguments or return value) that is used to signal back to the web page when something happens. It is defined very simply:

public event Action IsReady;

And is raised in the same way as most events:

if (IsReady != null)
{
   IsReady();
}

On the JavaScript side it is consumed like this:

  <script language="javascript" type="text/javascript">
  function MyX::IsReady() {
    alert("Ready");
  }
  </s

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.

IP Address Blocking or Restriction in SQL Server

  
"is it possible to block connections to SQL Server based on IP address". As far as now there is no official way in SQL Server to block the connections in SQL Server based on IP address. However this can be done from the OS end, we have the following three options available, refer HERE for more.


.Firewall
.IPSec
.RRAS IP Filter

WCF Tutorial - Events and Callbacks

  
we described how to make a very simple client/server application where clients would call functions on the server through a shared interface. In this tutorial, I'm going to expand that application to allow the server to execute functions on the client by using callbacks. Essentially, this is WCF's mechanism to allow events to be raised from the server to it's connected clients.

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.

Delegates and events in c#.net

  
People often find it difficult to see the difference between events and delegates. C# doesn't help matters by allowing you to declare field-like events which are automatically backed by a delegate variable of the same name. This article aims to clarify the matter for you. Another source of confusion is the overloading of the term "delegate". Sometimes it is used to mean a delegate type, and at other times it can be used to mean an instance of a delegate type. I'll use "delegate type" and "delegate instance" to distinguish between them, and "delegate" when talking about the whole topic in a general sense.

How to listen to events within a listview

  

Hi,

I've got a listview and I've put a button control in one of the columns, I'm trying to figure out how I have listen to the button click within a certain row, but can't see the button in the dropdown for the IDs I can generate events for.

I'd like to get the primary key of the row that's been clicked on and then run a sql statement against it.


Any help would be appreciated.


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.


UI Frontiers: Multi-Touch Manipulation Events in WPF

  

Multi-touch has progressed from being a futuristic prop of sci-fi films to a mainstream means of user interface. We'll show you how support for multi-touch in Windows 7 has filtered down and settled into various areas of the .NET Framework.

Charles Petzold

MSDN Magazine August 2010


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