Bernard Vander Beken
Bernard Vander Beken

Reputation: 5056

Does Assembly.GetManifestResourceStream(name) return a new stream on every call?

The documentation GetManifestResourceStream is not clear about multiple calls for the same resource. Does each call guarantee an independent stream instance?

Reason: know if one should worry about concurrent use.

Upvotes: 1

Views: 918

Answers (2)

Hans Passant
Hans Passant

Reputation: 941990

internal unsafe Stream GetManifestResourceStream(string name, ref StackCrawlMark stackMark, bool skipSecurityCheck)
{
    // blahblah
    //...
    return new UnmanagedMemoryStream(pointer, (long) length, (long) length, FileAccess.Read, true);
}

So, yes. It would be quite hard to use if it didn't.

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1502016

Given that streams are stateful, I would be highly surprised if two calls received the same Stream reference. It would surprise me much less to hear that two streams could both be views onto the same bit of memory, but that should be hidden from the caller.

I think it's reasonable to assume that the streams are independent.

Upvotes: 3

Related Questions