none
XmlSchemaSet Add async problem RRS feed

  • Question

  • When loading a schema through:

    Dim settings As XmlReaderSettings = New XmlReaderSettings()
    settings.Async = True
    Dim reader As XmlReader = XmlReader.Create(inputUri, settings)
    xmlSchema = xmlSchemaSet.Add(Nothing, reader) 

    The schema defined in the inputUri variable resolves using then proper GetEntityAsync function of the XmlUrlResolver. But the imported schemas resolve synchronously, which causes my ui to freeze while the schemas are being retrieved.

    How do I make the automatic imports schema (provided during the XmlSchemaSet.Add method) retrieval asynchronous?

    Thanks,

    Kingman B


    Saturday, January 26, 2019 4:28 PM

All replies

  • Maybe you can create a task:

    Await Task.Run(Sub()
                     ' load the schema
                     . . .
                   End Sub)


    Saturday, January 26, 2019 5:35 PM
  • That would unfreeze the UI I would guess, but doesn't that defeat the gains made by asynchronously loading the included/imported schemas?

    (And thanks for your quick reply)

    -Kingman 

    Sunday, January 27, 2019 7:37 PM
  • Hi,

    I think you need to try Viorel_'s solution to solve your problem,see the link:

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/await

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 29, 2019 5:50 AM
    Moderator
  • Hi Alex,

    Using Viorel_'s solution would free up the UI, but what I would like (if possible) is for the XmlSchemaSet.Add method to add the imported schemas asynchronously. There are two reasons for this:

    1. I use a progress bar to inform the user the status of the schema (and imported schema) loading. As the imports are starting to load, they report the size of the stream (if possible). If the load was asynchronous, the next import in queue  would start to load and report its length, increasing the total bytes requested and the denominator of the progress bar percentage complete calculation. As bytes are read, the numerator increases, moving the progress bar forwards. This method works well as I have written my own version of a XmlSchemaSet manager using asynchronous reads. I just want to use the .Net version because it is faster.

    2. When I wrote my own version I noticed significant time savings when I went "full async". I'd like to see the same from the XmlSchemaSet.Add. If an XmlSchema had 10 or so imports, asynchronous loading was over twice as fast.

    Thanks,

    Kingman

    Wednesday, January 30, 2019 2:57 PM
  • Hi,

    I have no good advice.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 11, 2019 2:24 AM
    Moderator