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

标签 vb.net multithreading global-asax

我是新手,但无法使此代码正常工作。 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/

相关文章:

VB.net MVC理解与绑定(bind)

vb.net - 为什么不对所有这些变量进行相同的处理?

multithreading - Win RT Metro C# MVVM 从工作线程更新 UI

c# - 从 WCF 服务读取全局应用程序属性

asp.net-mvc - 如何使用 SignalR 在 MVC 中实时通知?

asp.net - Global.asax 中 Application_End 处理程序内的 Server.MapPath

VB.NET - RichTextBox - 将格式应用于选定的文本

vb.net - 确定哪一行导致vb.net程序崩溃

c++ - 如何处理 std::thread 中的 PostMessage 线程消息?

java - 为什么当队列溢出且所有线程都忙时拒绝处理程序不调用