Everybody knows we are using multi threading platforms and we are developing multi threading applications. By the way, i couldn't recognize the thread issue. When i call a static method (that is in another class.) , which thread will be run ? does gui thread go the jobs and run method ? i.e: (i am gonna give vb code sample . Logic is the same with java.)
Private Sub runValuesTest_Click(sender As System.Object, e As System.EventArgs) Handles RunValuesTest.Click
DummyClass.Instance.DoJob()
End sub()
This is vb syntax but it does not matter . the main logic is the same with C# and Java. When i click the button, will be new thread run ? Or gui thread go job ?
If new thread will be run, why and when do we use New Thread to our jobs ?
If gui thread goes, I see lots of time more than one thread run in a program. how can threads be different in a program? why and when thread exceptions occurs somehow ? For example: i am doing file operation in this method: (this may be different question)
Private _file As System.IO.StreamWriter
Private Sub runValuesTest_Click(sender As System.Object, e As System.EventArgs) Handles RunValuesTest.Click
If Not Directory.Exists("GraphXml") Then
Directory.CreateDirectory("GraphXml")
End If
_fileName = "GraphXml\Graph_" & txtName & ".xml"
_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
When i click so fast (1 click per two seconds) , it gives error "Another process uses file".
If this gui thread , why does it give error ?
If it is new thread , why do we do some staffs like gui operations in button click method. ? (Everybody knows , to do gui operations , we want to use gui thread, am i right?)
This second code part may be different question but i just want to learn logic behind of the THREAD for .net ( I think the logic is also valid for java)
Thanks
Edit: this may not be relevant with JAVA. Although i give vb code sample, i added the java tag because i think the logic is the same.