Will I have a thread conflict with this?

D

darrel

I'm still trying to wrap muy head around preventing thread conflicts. I have
a class that has two functions in it. This is called from various part of my
application and will generate a XML file. I've gotten lots of advice on
this, and am looking for a check on where I'm at. Am I missing some
concepts. Prior to this, I was using synclock to lock a filestream, however,
this time I'm not writing to a file, so not sure if I need a synclock or
not.

My concen is if the first function is called, and starts running the second
function while the first is called by another thread...would that lead to
the second function sending the wrong data back?

Public Class menuWriterToDB

Shared Sub createXMLfileWithXmlWriter(ByVal parentNode As Integer, ByVal
intLevel As Integer, ByVal siteID As Integer)

Try

Dim sbXML As New System.Text.StringBuilder
Dim swXML As New System.IO.StringWriter(sbXML)
Dim twXML As New System.xml.XmlTextWriter(swXML)

twXML.Formatting = twXML.Formatting.Indented
twXML.Indentation = 3
twXML.WriteStartDocument()
twXML.WriteComment("Created on " & Now())
twXML.WriteStartElement("menuItems")

' this calls the other function to begin the recursive DB call and
building of the XML
WriteXmlData(twXML, parentNode, siteID)

twXML.WriteEndElement() 'close menuItems node
twXML.WriteEndDocument() 'close docment

'create a DB connection and save the XML (sbXML.ToString) into it

twXML.Flush()
twXML.Close()

Catch ex As Exception
' catch errors
Finally
End Try
End Sub

Shared Sub WriteXmlData(ByVal objXMLWriter As System.Xml.XmlTextWriter,
ByVal parentNode As Integer, ByVal siteID As Integer, Optional ByVal
intLevel As Int32 = 0)

' grab all the data from the DB...

While rowCount < DS.Tables(0).Rows.Count 'ie, if there IS data,
then...
objXMLWriter.WriteStartElement("menuItem")

' write out all the nodes...
objXMLWriter.WriteElementString...

'now call the subroutine we're in to see if this value has
'any children and increase the indent, and so on...
WriteXmlData(objXMLWriter,
Convert.ToInt32(DS.Tables(0).Rows(rowCount).Item(0)), siteID, intLevel + 1)

rowCount = rowCount + 1
End While

' clean up
objConnect.Close()
objOleDbAdapter.Dispose()
objCommand.Dispose()
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top