gpt4 book ai didi

vb.net - System.Threading.Timer不触发,global.aspx

转载 作者:行者123 更新时间:2023-12-03 13:13:38 25 4
gpt4 key购买 nike

我是新手,但无法使此代码正常工作。 FileSweeper应该启动一个微调器,以触发Web服务器上的fileCopy。 fileSweeoer由global.asax触发。然后,FileCopy将复制文件。但是,FC.copy永远不会触发。任何帮助/解释都将有所帮助!

如果这是一个在Web服务器上运行的类,会有所不同吗?

我的代码来自http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx

Imports Microsoft.VisualBasic
Imports System
Imports System.Threading

Public Class fileSweeper

Dim stateTimer As Timer

<MTAThread()> _
Sub Main()
Dim FC As New fileCopy
Dim tcb As TimerCallback = AddressOf FC.Copy

stateTimer = New Timer(tcb, "", 20000, 200000)
GC.KeepAlive(stateTimer)
End Sub

末级

Global.asax:
<%@ Application Language="VB" %>

<script runat="server">

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Dim FS As New fileSweeper
FS.Main()
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub

</script>

最佳答案

您可能会在这里获得意外的结果,因为您可能会在Web服务器上获得多个 session 。您可能要考虑创建控制台应用程序并使用Windows Task Scheduler。

关于vb.net - System.Threading.Timer不触发,global.aspx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6947347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com