none
Multiple access to embedded resources inside a .net assembly RRS feed

  • Question

  • I developed a .net assembly that uses embedded resources(xsd and xslt files) to validate and transform XML files.

    The embedded resources are accesed using streams with: assembly.GetManifestResourceStream() The resources are only read not written.

    Here is the code I use to access these embedded resources: 

    Assembly myAssembly = Assembly.GetExecutingAssembly();
    using (Stream schemaStream = myAssembly.GetManifestResourceStream(resourceName)) {
      using (XmlReader schemaReader = XmlReader.Create(schemaStream)) {
        settings.Schemas.Add(null, schemaReader);
      }
    }

    I want to use this assembly with a .NET web service but I have a very big fear: 

    If a lot of users hit the web service, a lot of users are going to access these embedded resources at the same time. I don´t know if a embedded resource can support acces by multiple readers. 

    Can embeded resources be accesed by multiple users(readers) in this way? 

    Thanks in advance for your help. 

    Friday, January 10, 2014 6:38 PM

Answers

  • Since it is read only there will be no issues with multiple users reading the same resource at the same time.  However performance may not be great if there are a large # of users at once.  After you get it working you might consider loading the resource only once and storing it in cache if you expect it to be heavily used.  I wouldn't do this unless performance becomes an issue though.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, January 10, 2014 8:14 PM
    Moderator

All replies

  • Since it is read only there will be no issues with multiple users reading the same resource at the same time.  However performance may not be great if there are a large # of users at once.  After you get it working you might consider loading the resource only once and storing it in cache if you expect it to be heavily used.  I wouldn't do this unless performance becomes an issue though.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Friday, January 10, 2014 8:14 PM
    Moderator
  • Agree with Micheal if only perf is an issue cache it, so there is no reload of resouces.
    Friday, January 10, 2014 8:16 PM
  • To my knowledge embedded resources are memory streams mapped into the memory space of the assembly. Resources are read-only memory objects why - "performance may not be great if there are a large # of users at once"? Resource is already in memory, its read-only so concurrency should not be an issue, what am I missing?

    Couple of references:

    Stackoverflow question

    Another stackoverflow question (less relevant)

    Cheers,
    Taras

    Tuesday, March 11, 2014 10:49 PM