Async to Sync

  • Thread starter Thread starter OpticTygre
  • Start date Start date
O

OpticTygre

How can I make the following code synchronous? TIA.

Public Sub ValidateXMLAgainstSchema(ByVal XSchema As XmlSchema, ByVal XData
As String)

Dim XSchemaset As XmlSchemaSet = New XmlSchemaSet

XSchemaset.Add(XSchema)

Dim XSettings As XmlReaderSettings = New XmlReaderSettings

XSettings.ValidationType = ValidationType.Schema

XSettings.Schemas = XSchemaset

Dim xStringReader As StringReader = New StringReader(XData)

Dim XReader As XmlReader = XmlReader.Create(xStringReader, XSettings)

AddHandler XSettings.ValidationEventHandler, AddressOf ValidationCallBack

While XReader.Read

'If there are errors, an asynchronous call would be made to the

'ValidationCallBack sub. How can we make this synchronous, so this

'sub can be made a function which would return a boolean, or a collection

'of ValidationEventArgs that we could return?

End While

End Sub

Private Shared Sub ValidationCallBack(ByVal sender As Object, ByVal e As
ValidationEventArgs)

MessageBox.Show("Error occurred. " & e.Message, "Validation Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)

End Sub
 
Async,

I did that this morning found it somewhere don't remember, maybe you can
help with this delima since your working with xml. I can't get treeview to
work with xmldatasource when I have xmlns attribute in the xmlfile.

private _valid as boolean
Private Sub ValidationCallBack(ByVal sender As Object, ByVal e As
ValidationEventArgs)
_valid = False
End Sub

Public Function ValidateXMLAgainstSchema(ByVal XSchema As XmlSchema, ByVal
XData As String) as boolean
_valid = true
....
same code as in sub validatexmlagainstschema
....
return _valid
end function

It appears to be working for me but no guarantees.
Good Luck
DWS
 
Back
Top