i am working with a file. this is code:
Private Sub WriteXml(ByVal txtName As String)
If Not Directory.Exists("GraphXml") Then
Directory.CreateDirectory("GraphXml")
End If
_fileName = "GraphXml\Graph_" & txtName & ".xml"
Dim checkCondition As Boolean = False
_file = My.Computer.FileSystem.OpenTextFileWriter(_fileName, False)
_file.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
_file.WriteLine("<n0>")
DepthFirstSearch(StaticService.AllNodes(0))
_file.WriteLine("</n0>")
_file.Close()
_file.Dispose()
End Sub
This method is called when button is clicked. If i do 1 click per 2 seconds, gives error: "another process uses file" . I could not understand the problem because i use file.close . I thought this may be relevant with threading problem and i asked this question link: and i tried with thread. code like this:
when a method is called , which thread will be run in c# and java?
and i tried with thread. code like this:
Dim thread As Threading.Thread = Nothing
Public Sub CreateXml()
'cok hızlı tıklandıgı zaman xml olusturmak için çalışan thread önceki thread in file.close yapmasını bekler
' If Not checkThread Then
Dim txtName As String = InputTxt.Items(InputTxt.SelectedIndex)
txtName = txtName.Substring(0, txtName.IndexOf("."))
While Not IsNothing(thread) AndAlso thread.IsAlive
Dim a = ""
' wait loop
End While
thread = New Threading.Thread(Sub() WriteXml(txtName))
thread.IsBackground = False
thread.Start()
End Sub
This is also not working. i could not find any suggestions. I am gonna wait for responds.
Thanks