Thread Sleep in Classic ASP?

后端 未结 12 2098
滥情空心
滥情空心 2021-02-05 23:10

I\'m doing some revision on an old app that is written in classic ASP/VbScript.

It has a feature to send out an e-mail to the members of the application, but because the

相关标签:
12条回答
  • 2021-02-05 23:12

    You can use :

    <html>
    <head>
        <title>Sleep</title>
    </head>
    <body>
        <% 
    
            function Sleep(seconds)
                set oShell = CreateObject("Wscript.Shell")
                cmd = "%COMSPEC% /c timeout " & seconds & " /nobreak"
                oShell.Run cmd,0,1
            End function
    
            Sleep(5)
    
            response.write("End") 
        %>
    </body>
    </html>
    
    0 讨论(0)
  • 2021-02-05 23:13

    Are you using CDO? Since this is tagged as classic ASP I'm guessing so.

    If so if you can use

    myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=1 '(which is send using pickup)

    instead of

    myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 '(which is send using port)

    It's more reliable because it writes the email to file (usually C:\inetpub\mailroot\pickup) and IIS's SMTP server checks the folder for new mail and will retry if it fails the first time. The catch is you have to set up SMTP within the IIS snap in.

    0 讨论(0)
  • 2021-02-05 23:16

    If you are using SQL Server with ASP classic you can use WAITFOR "query" to stall the script for seconds or even milliseconds:

    WAITFOR DELAY '00:00:01.234' -- 1,234 ms
    
    0 讨论(0)
  • 2021-02-05 23:17
    var shell = Server.CreateObject("WScript.Shell");
    shell.run("CHOICE /C:AB /D:A /T:1 > NUL", 1, true);
    
    0 讨论(0)
  • 2021-02-05 23:17

    The answer is don't use the server to wait, use the client. You can write a javascript that keeps calling Send() every second using setInterval until the queue is empty.Use an Ajax call to send one email using a server side script. Then on return of the ajax call you can also indicate in the html page that an email has been sent.

    0 讨论(0)
  • 2021-02-05 23:25

    Sorry that this answer is not strictly related to the question, but in trying to answer a question, it just got way to big for comments.

    @shahka, the difference is, when you are trying to connect to a DB, the code enters a "wait state", (like a callback), so no CPU time is used. It matters not about what the SESSION or THREAD is doing, it matter what ELSE the CPU/Core is doing.

    For an example, find an older non-multi-core CPU. Setup your sample to sleep for 10 seconds, then run for 2-5 seconds or so, then sleep again for 10. Do that about 20,000 times. While it's running, try and use box, see just how responsive it is. Move windows around, watch the CPU usage, etc.

    THAT gives you an exmaple of what's happening to this man's Web server. It becomes unresponsive, because the thread scheduler will tend to 'favor' the CPU/Core that is NOT "spun up" (as we call it). So, ALL web requests, OS operations, etc will happen on the OTHER core, thus over-loading it, giving it a feeling of being "spun up" as well.

    Now, you have times when you can tight-loop a CPU and it will not matter. But, in all my years of programming, I've never found it necessary to write a tight loop like that (on purpose). Some of it comes back around to doing things the right way, and the wrong way. Doing something the wrong way will often WORK, but that does not mean it wworks CORRECTLY.

    If you want a good example of this, go and pick just about any virus on the planet, and analyze it. You'll find that it order to do damage, they (virus writers) often have to do things the "wrong" way. Sure, it gets the job done, but it also breaks the virus on say, a different language version of Windows, or it crashes the whole machine negating it's purpose, etc.

    Greg Hewgill was one of my early teachers about this type of stuff, and since I worked with him for many years, and supported, and later QA'ed his software, I learned a lot from him, much in the same waay I'm trying to tell you why your code sample is not good. strictly speaking, the code is fine. It works. It's well written. But, it does not FUNCTION correctly, and has adverse side effects that other, maaybe amature programmers who might be reading this looking for knowledge do not fully understand. THAT'S why I did not recommend your sample.

    0 讨论(0)
提交回复
热议问题