Microsoft KB Archive/247319: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 51: Line 51:
== CAUSE ==
== CAUSE ==


PUBLIC variables declared within an in-process OLE Automation Server are public to the thread and any object on the thread. PUBLIC variables are not released until the thread has been uninitialized and the client has unloaded the in-process server. Setting the instance of the in-process server object to &quot;nothing&quot; does not unload the server.
PUBLIC variables declared within an in-process OLE Automation Server are public to the thread and any object on the thread. PUBLIC variables are not released until the thread has been uninitialized and the client has unloaded the in-process server. Setting the instance of the in-process server object to "nothing" does not unload the server.


</div>
</div>
Line 84: Line 84:
       lnSecs=IIF(EMPTY(lnSecs),0,lnSecs)
       lnSecs=IIF(EMPTY(lnSecs),0,lnSecs)


       IF lnSecs &gt; 60
       IF lnSecs > 60
         lnSecs = 61
         lnSecs = 61
       ENDIF
       ENDIF


       IF VARTYPE(gnPubValue) = &quot;N&quot;
       IF VARTYPE(gnPubValue) = "N"
         gnPubValue = gnPubValue + 1
         gnPubValue = gnPubValue + 1
       ELSE
       ELSE
Line 95: Line 95:
       ENDIF
       ENDIF


       IF VARTYPE(gnPrivValue) = &quot;N&quot;
       IF VARTYPE(gnPrivValue) = "N"
         gnPrivValue = gnPrivValue + 1
         gnPrivValue = gnPrivValue + 1
       ELSE
       ELSE
Line 110: Line 110:


       DECLARE INTEGER GetCurrentThreadId IN WIN32API
       DECLARE INTEGER GetCurrentThreadId IN WIN32API
       lcHTML = [<p&gt;<table style=&quot;background:black;color:white&quot;&gt;] + CHR(13) + ;
       lcHTML = [<p><table style="background:black;color:white">] + CHR(13) + ;
         [<tr&gt;<td style=&quot;font:normal normal 14pt Verdana&quot;&gt;] + ;
         [<tr><td style="font:normal normal 14pt Verdana">] + ;
         &quot;The request completed in &quot; + TRANS(lnSecs) + &quot; seconds.&quot; + [</td&gt;</tr&gt;] +CHR(13) +;
         "The request completed in " + TRANS(lnSecs) + " seconds." + [</td></tr>] +CHR(13) +;
         [<table&gt;] + CHR(13) + ;
         [<table>] + CHR(13) + ;
         &quot;The current Thread ID is: &quot; + TRANS(GetCurrentThreadId()) + &quot;<p&gt;&quot;+CHR(13) + ;
         "The current Thread ID is: " + TRANS(GetCurrentThreadId()) + "<p>"+CHR(13) + ;
         &quot;The Public Value  (gnPubValue) : = &quot; + TRANS(gnPubValue) + &quot;<br&gt;&quot;+ CHR(13) + ;
         "The Public Value  (gnPubValue) : = " + TRANS(gnPubValue) + "<br>"+ CHR(13) + ;
         &quot;The Private Value (gnPrivValue): = &quot; + TRANS(gnPrivValue) + &quot;<br&gt;&quot;
         "The Private Value (gnPrivValue): = " + TRANS(gnPrivValue) + "<br>"


       RETURN lcHTML
       RETURN lcHTML
Line 126: Line 126:
<li>Register the COM Server.</li>
<li>Register the COM Server.</li>
<li><p>Create an Active Server Page named '''TEST.ASP''' in the IIS WWWROOT directory using the following code, and make certain that the directory has execute privileges:</p>
<li><p>Create an Active Server Page named '''TEST.ASP''' in the IIS WWWROOT directory using the following code, and make certain that the directory has execute privileges:</p>
<pre class="codesample"><%@ Language=VBScript %&gt;
<pre class="codesample"><%@ Language=VBScript %>
<HTML&gt;
<HTML>
<HEAD&gt;
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;&gt;
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD&gt;
</HEAD>
<BODY&gt;
<BODY>


<%
<%
Set oVFPApp = Server.CreateObject(&quot;mthread.mthread&quot;)
Set oVFPApp = Server.CreateObject("mthread.mthread")


Response.Write oVFPApp.PublicHit
Response.Write oVFPApp.PublicHit
Line 140: Line 140:
set oVFPApp = nothing
set oVFPApp = nothing


%&gt;    
%>    


</BODY&gt;
</BODY>
</HTML&gt;</pre></li>
</HTML></pre></li>
<li>Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Refresh the page several times, and note that the value of gnPubValue is incremented each time the page is refreshed.</li>
<li>Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Refresh the page several times, and note that the value of gnPubValue is incremented each time the page is refreshed.</li>
<li>Close your Web Browser.</li>
<li>Close your Web Browser.</li>

Latest revision as of 13:53, 21 July 2020

Article ID: 247319

Article Last Modified on 12/11/1999



APPLIES TO

  • Microsoft Visual FoxPro 6.0 Professional Edition



This article was previously published under Q247319

SYMPTOMS

Public variables declared in an in-process Microsoft Visual FoxPro OLE Automation Server, launched from an ASP page, are not released when the OLE Automation Server is released.

CAUSE

PUBLIC variables declared within an in-process OLE Automation Server are public to the thread and any object on the thread. PUBLIC variables are not released until the thread has been uninitialized and the client has unloaded the in-process server. Setting the instance of the in-process server object to "nothing" does not unload the server.

RESOLUTION

Set the scope of variables used within in-process OLE Automation Servers, used with Active Server Pages, to PRIVATE rather than PUBLIC.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new project named MTHREAD.
  2. Add a new program file to the project, using the following code:

    DEFINE CLASS mthread AS CUSTOM OLEPUBLIC
    
       FUNCTION PublicHit
          LPARAMETER lnSecs
          LOCAL x
          lnSecs=IIF(EMPTY(lnSecs),0,lnSecs)
    
          IF lnSecs > 60
             lnSecs = 61
          ENDIF
    
          IF VARTYPE(gnPubValue) = "N"
             gnPubValue = gnPubValue + 1
          ELSE
             PUBLIC gnPubValue
             gnPubValue = 1
          ENDIF
    
          IF VARTYPE(gnPrivValue) = "N"
             gnPrivValue = gnPrivValue + 1
          ELSE
             PRIVATE gnPrivValue
             gnPrivValue = 1
          ENDIF
    
          DECLARE Sleep IN WIN32API INTEGER
          FOR x=1 TO lnSecs
             FOR x=1 TO lnSecs
                Sleep(1000)
             ENDFOR
          ENDFOR
    
          DECLARE INTEGER GetCurrentThreadId IN WIN32API
          lcHTML = [<p><table style="background:black;color:white">] + CHR(13) + ;
             [<tr><td style="font:normal normal 14pt Verdana">] + ;
             "The request completed in " + TRANS(lnSecs) + " seconds." + [</td></tr>] +CHR(13) +;
             [<table>] + CHR(13) + ;
             "The current Thread ID is: " + TRANS(GetCurrentThreadId()) + "<p>"+CHR(13) + ;
             "The Public Value  (gnPubValue) : = " + TRANS(gnPubValue) + "<br>"+ CHR(13) + ;
             "The Private Value (gnPrivValue): = " + TRANS(gnPrivValue) + "<br>"
    
          RETURN lcHTML
       ENDFUNC
    ENDDEFINE
                        
  3. Click the Build button on the Project Manager, and select either a Single-threaded COM server (dll) or a Multi-threaded COM server (dll).
  4. Install the COM Server and run-time files on a computer running Internet Information Server.
  5. Register the COM Server.
  6. Create an Active Server Page named TEST.ASP in the IIS WWWROOT directory using the following code, and make certain that the directory has execute privileges:

    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <BODY>
    
    <%
    Set oVFPApp = Server.CreateObject("mthread.mthread")
    
    Response.Write oVFPApp.PublicHit
    
    set oVFPApp = nothing
    
    %>   
    
    </BODY>
    </HTML>
  7. Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Refresh the page several times, and note that the value of gnPubValue is incremented each time the page is refreshed.
  8. Close your Web Browser.
  9. Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Note that the value of gnPubValue is not 1.


REFERENCES

156547 HOWTO: Manually Register a Custom OLE Server


156014 HOWTO: Set Up OLE Automation in Visual FoxPro


Keywords: kbautomation kbprb KB247319