471,591 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,591 software developers and data experts.

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

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)


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.WriteComment("Created on " & Now())

' 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


Catch ex As Exception
' catch errors
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,

' write out all the nodes...

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

rowCount = rowCount + 1
End While

' clean up
End Sub
End Class
May 25 '06 #1
0 900

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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.