I have the following code below that when run it always returns me the error that is being used by another process. I guarantee there is no other process open with it!
#Region "Declaração DLL"
Dim ServerMaster As ServiceNetwork_ServerMasterSecurity
#End Region
#Region "Escritor"
#End Region
#Region "Declaração De String's"
Dim LocalAPPProc As String = Application.StartupPath & "\Server Master\AntiDebugger\Cache Process Kill"
#End Region
#Region "Date"
Dim Data As DateTime = Date.Now
#End Region
Public Sub IniciarProcessoFolder()
If Directory.Exists(LocalAPPProc & "\" & Data.Year) Then
VerificarSubPastas()
Else
Directory.CreateDirectory(LocalAPPProc & "\" & Data.Year)
IniciarProcessoFolder()
End If
End Sub
Private Sub VerificarSubPastas()
Dim Local As String = LocalAPPProc & "\" & Data.Year.ToString()
Dim MesFolder As Integer = 12
For i As Integer = 1 To MesFolder
If Directory.Exists(Local & "\" & i) Then
i += 1
Else
Directory.CreateDirectory(Local & "\" & i)
Thread.Sleep(20)
End If
If i = 12 Then
VerificarStringProcess()
End If
Next
End Sub
Private Sub VerificarStringProcess()
Dim LerProcessKill As String() = File.ReadAllLines(LocalAPPProc & "\ProcKill.lg")
''Primeiro Verificar Se Tem Alguma String
If LerProcessKill(0) <> "" Then
EscreverProcesso()
Else
MsgBox("O Processo não pode ser gravado no cache por não conter string valida.", MsgBoxStyle.Exclamation, "AntiDebuggers")
End If
End Sub
Private Sub EscreverProcesso()
Dim Dia As String = Data.DayOfWeek
Dim Mes As String = Data.Month.ToString()
Dim Ano As String = Data.Year.ToString()
Dim Hora As String = Data.Hour & "." & Data.Minute.ToString()
Dim Seconds As String = Data.Second.ToString()
Dim DateComplete As String = Dia & "." & Mes & "." & Ano & "." & Hora & "." & Seconds & ".log"
Dim LC As String = LocalAPPProc & "\" & Ano & "\"
If Directory.Exists(LocalAPPProc & "\" & Data.Year) Then
''Cria o arquivo de log
File.CreateText(LC & Mes & "\" & DateComplete)
''Chama o escritor
Escreve()
Else
MsgBox("A Pasta de log's não existe.", MsgBoxStyle.Exclamation, "AntiDebuggers:0x003")
End If
End Sub
Private Sub Escreve()
Dim Dia As String = Data.DayOfWeek
Dim Mes As String = Data.Month.ToString()
Dim Ano As String = Data.Year.ToString()
Dim Hora As String = Data.Hour & "." & Data.Minute.ToString()
Dim Seconds As String = Data.Second.ToString(0)
Dim LC As String = LocalAPPProc & "\" & Ano & "\"
Dim DateComplete As String = Dia & "." & Mes & "." & Ano & "." & Hora & "." & Seconds & ".log"
Dim Escritor As StreamWriter
Escritor = New StreamWriter(LC & Mes & "\" & DateComplete) ''<< Aqui é o problema
Dim ProcessKill As String() = System.IO.File.ReadAllLines(Application.StartupPath & "\Server Master\AntiDebugger\Cache Process Kill\ProcKill.lg")
Escritor.WriteLine("Process Kill: " & ProcessKill(0))
Escritor.WriteLine("Date Kill: " & Date.Now)
Escritor.Close()
''Reinicia o timer do server master
' Dim Serv As New ServiceNetwork_ServerMasterSecurity
' Serv.TAntiDebugger.Start()
End Sub
The problem occurs when I declare a new Instance in StreamWriter
.
Can anyone help me?