J'ai une application multi-thread qui écrit le journal dans un fichier. occasionaly, sauvegarde échoue en utilisant ce codeÉchec de l'écriture dans un fichier dans une application multithread vb.net
Friend Sub SaveToText(ByVal FileName As String, ByVal Text As String)
'// create a writer and open the file
Dim objLock As New Object
SyncLock objLock
Dim tw As TextWriter = Nothing
Try
'// write a line of text to the file
tw = New StreamWriter(FileName, True)
tw.Write(Text)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error saving", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Finally
'// close the stream
If tw IsNot Nothing Then
tw.Close()
tw.Dispose()
End If
End Try
End SyncLock
End Sub
Le message d'erreur que je reçois
Le processus ne peut pas accéder au fichier « error.log » car il est utilisé par un autre processus.
De quelle autre manière puis-je rendre ce coffre-fort?
Quel autre processus verrait ce fichier verrouillé? Votre scanner de virus? Une autre copie de votre programme? Un programme différent? –