Private Sub ChangedCallback(ByVal sender As Object, ByVal e As NetworkAvailabilityEventArgs)ĭim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()Īnd your code written like this does nothing. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadĪddHandler NetworkChange.NetworkAvailabilit圜hanged, AddressOf ChangedCallback The same issue occurs with your code written like this. Since my code is really no different than your code except for the instantiation of the sub I don't really see the issue. Just like GOTO or DoEvents.Īlthough I've not tested my code or your code in a service. But being bad doesn't mean you can't use it. You can use GOTO or DoEvents, I wont say nothing,īut this is BAD: "CheckForIllegalCrossThreadCalls = False" WriteLog("UNEXPECTED ERROR: " & ex.Message & ": " & ex.InnerException.Message) WriteLog("UNEXPECTED ERROR: " & ex.Message) If blnLogSuccess Then WriteLog("Imported ") If ioLineData(1) "" Then dataRecord.Value2 = ioLineData(1) If lineNumber >= 88 And lineNumber "" Then dataRecord.Value1 = ioLineData(1) WriteLog("ERROR: Cannot determine sample type or ID")ĭataRecord = (From c In DBContext.Lab_PSA_Results Where c.SampleID = SampleID And c.SampleType = SampleType And c.ParticleSize = ioLineData(0) Select c).FirstOrDefaultĭataRecord = (From c In DBContext.Lab_PSA_Results Where c.SampleID = SampleID And c.SampleType = SampleType And c.SampleSubType = SampleSubType And c.ParticleSize = ioLineData(0) Select c).FirstOrDefault WriteLog("ERROR: Could not read sample subtype: AA or SP") If SampleSubType "AA" And SampleSubType "SP" Then WriteLog("ERROR: Invalid Heat Number in ") WriteLog("ERROR: Invalid Blend Number in ")ĮlseIf Mid(ioLineData(1), 1, 1) = "B" Or Mid(ioLineData(1), 1, 1) = "C" Then WriteLog("ERROR: is not in the correct file format.") 'The file may not be ready for opening yet as FileCreated fires at start of creation, 'so we'll have to keep trying till it's ready: Max of 1 minute, then give up Private Sub _Watcher_Created(sender As Object, e As FileSystemEventArgs) Handles _Watcher.Createdĭim SampleType As String = "" 'Blend or Heatĭim SampleSubType As String = "" 'AA or SPĭim SampleID As String = "" 'BlendID or HeatIDĭim blnIsFirst As Boolean = True 'is this Value1 or Value2?ĭim strLogSetting As String = ("LogErrorsOnly") _Watcher.NotifyFilter = NotifyFilters.FileName _Watcher = New FileSystemWatcher(strDir, strFilter) Protected Overrides Sub OnStart(ByVal args() As String)ĭim strDir As String = ("ImportDirPath") Here is the code:ĭim WithEvents _Watcher As FileSystemWatcher I would appreciate any ideas about what could be going wrong. It is handling files exported by a lab machine - there is at least 5 minutes between files being added and there are only about 20 files in a day. The only thing I found online about issues with the FileSystemWatcher had to do with its internalīuffer but I don't believe that is the problem because this is not a high volume directory. It has now been running for two days without issue but obviously it's just a matter of time before it happens again. I stopped and restarted the service and it started working again. There were no errors in the windows event log or in my program generated log file. Responding to new files in the watched directory. This was running flawlessly for about a week, then 1 day it stopped I created a windows service project which instantiates a FileSystemWatcher in the OnStart event and then responds to the file created event whenever a file is created in the watched directory.
0 Comments
Leave a Reply. |