467,135 Members | 1,181 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,135 developers. It's quick & easy.

Will I have a thread conflict with this?

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
May 25 '06 #1
  • viewed: 839
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Web Developer | last post: by
reply views Thread by dls | last post: by
2 posts views Thread by awalter1 | last post: by
1 post views Thread by =?Utf-8?B?ZGF2aWQ=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.