Microsoft KB Archive/271787

= PRB: Application.Lock and Application.UnLock Cause Server to Hang in IIS 5.0 =

Article ID: 271787

Article Last Modified on 6/25/2004

-

APPLIES TO


 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q271787



SYMPTOMS
When you modify Application variables from within a component that is called from an Active Server Pages (ASP) page, your server may stop responding (hang). The code in the component that causes the problem resembles the following: Application.Lock Application(&quot;myvar&quot;) = &quot;hello world&quot; Application.UnLock



CAUSE
Code that is embedded in the Application.Lock and Application.UnLock methods provides protection in a multi-user environment. With the introduction of COM+, Internet Information Server (IIS) 5.0 takes advantage of the Thread-Neutral Apartment (NA) when accessing the Application object. As a result, when you explicitly call Application.Lock and Application.UnLock from within a component, under certain scenarios you might encounter a deadlock scenario that causes the server to stop responding. This problem is most commonly seen when ASP intrinsics are marshalled back and forth between the IIS server and the COM+ Application server. The following two scenarios may cause the server to hang:
 * When you debug a Microsoft Visual Basic component from the Visual Basic Integrated Development Envrionment (IDE).
 * When you call a component that is running as a Server application in COM+.



RESOLUTION
The Application.Lock and Application.UnLock methods are not needed to assign a single Application variable because the methods are called internally.

If you need to assign multiple Application variables within the same Application.Lock and Application.UnLock methods from your component, your component must run in the same process as the caller, or you must modify your logic to only include a single assignment. For example, the following code Application.Lock Application(&quot;myvar1&quot;) = &quot;hello&quot; Application(&quot;myvar2&quot;) = &quot;world&quot; Application.UnLock could be modified to work around this issue as follows: Dim array(1) array(0) = &quot;hello&quot; array(1) = &quot;world&quot; Application(&quot;myvar&quot;) = array NOTE: This is only one example. There are numerous ways that you can change your logic to work around this issue.



Steps to Reproduce Behavior
 In Visual Basic, create a new ActiveX DLL project. Add a reference to the following libraries:

COM+ Services Type Library

Microsoft Active Server Pages Object Library

  Add the following code to the class module: Implements ObjectControl

Private oContext As ObjectContext Private oApplication As ASPTypeLibrary.Application

Private Sub ObjectControl_Activate Set oContext = GetObjectContext Set oApplication = oContext(&quot;Application&quot;) End Sub

Private Sub ObjectControl_Deactivate Set oContext = Nothing Set oApplication = Nothing End Sub

Private Function ObjectControl_CanBePooled As Boolean ObjectControl_CanBePooled = False End Function

Public Sub IISHang

oApplication.Lock oApplication(&quot;test&quot;) = &quot;World&quot; '<= App HANGS here oApplication.UnLock

End Sub  Compile the DLL and register the component with COM+. Make sure that the COM+ package's Activation type is set to Server application.  Create a new ASP page and paste the following code: <%   Dim obj Set obj = Server.CreateObject(&quot;Project1.Class1&quot;) Call obj.IISHang Set obj = nothing %>                    Run the ASP page to cause the server to stop responding.</li></ol>

Additional query words: IIS5 HANG Application LOCK UNLOCK VB COM+

Keywords: kbprb KB271787

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.