У нас есть существующая служба Windows, которая перемещает файлы (7 файлов, 5 * event.xdf, 1 statistics.xdf и 1 файл order.xdf) и перевести его в xml.VB.NET - Как скопировать файл перед его переносом другими службами
Я создал службу Windows, которая копирует все 7 файлов, прежде чем переместить их другими службами Windows. Я могу копировать только 3 * event.xdf, 1 statistics.xdf и 1 order.xdf.
Пропустить 2 event.xdf.
Вот моя логика для кода
создать поток для каждого отдельного файла и скопировать каждый.
Копировать событие в папку Temp:
thXDFevent = New System.Threading.Thread(AddressOf backup_xdf_events)
thXDFevent.IsBackground = True
thXDFevent.Start()
'order
thXDForder = New System.Threading.Thread(AddressOf backup_xdf_order)
thXDForder.IsBackground = True
thXDForder.Start()
'statistics
thXDFstatistics = New System.Threading.Thread(AddressOf backup_xdf_statistics)
thXDFstatistics.IsBackground = True
thXDFstatistics.Start()
Функции:
Private Sub backup_xdf_events()
Try
While (True)
getXDFevents()
End While
Catch ex As Exception
'EventLog1.WriteEntry("Services XDF error:" & strDate.ToString)
End Try
End Sub
Private Sub getXDFevents()
Dim f As String
For Each f In Directory.GetFiles("C:\POS\", "*event.xdf")
My.Computer.FileSystem.CopyFile("C:\POS\" & Path.GetFileName(f), xdf_temp & Path.GetFileName(f), True)
Next f
System.Threading.Thread.Sleep(500)
End Sub
Private Sub backup_xdf_order()
Try
While (True)
getXDForder()
End While
Catch ex As Exception
'EventLog1.WriteEntry("Services XDF error:" & strDate.ToString)
End Try
End Sub
Private Sub getXDForder()
Dim f As String
For Each f In Directory.GetFiles("C:\POS\", "*order.xdf")
My.Computer.FileSystem.CopyFile("C:\POS\" & Path.GetFileName(f), xdf_temp & Path.GetFileName(f), True)
Next f
System.Threading.Thread.Sleep(500)
End Sub
Private Sub backup_xdf_statistics()
Try
While (True)
getXDFstatistics()
End While
Catch ex As Exception
'EventLog1.WriteEntry("Services XDF error:" & strDate.ToString)
End Try
End Sub
Private Sub getXDFstatistics()
Dim f As String
For Each f In Directory.GetFiles("C:\POS\", "*statistics.xdf")
My.Computer.FileSystem.CopyFile("C:\POS\" & Path.GetFileName(f), xdf_temp & Path.GetFileName(f), True)
Next f
System.Threading.Thread.Sleep(500)
End Sub
Не является ли это именно то, что [FileSystemWatcher] (https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx) для ? – MrGadget