I am a newbie, but I am unable to get this code working. FileSweeper is supposed to start a timmer that triggers fileCopy on a web server. fileSweeoer is triggered by global.asax. FileCopy then will copy the file. However the FC.copy never fires. Any help/explanation would be helpful!
Would it make any difference if this was a class running on a web server?
My code is from 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
End Class
Global.asax:
<%@ Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal se开发者_运维技巧nder 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>
You are probably going to get unexpected results here because you are likely going to get multiple sessions on a web server. You might want to consider creating a console app and using windows task scheduler.
精彩评论