Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How Do I Synchronize Multithreaded Access to a Generic Type?

0
Posted

How Do I Synchronize Multithreaded Access to a Generic Type?

0

In general, you should not use a Monitor on generic type parameters. The reason is that the Monitor can only be used with reference types. When you use generic types, the compiler cannot tell in advance whether you will provide a reference or a value type parameter. In C#, the compiler will let you use the lock() statement, yet if you provide a value type as the type parameter, it will have no effect at runtime. In Visual Basic, the compiler will not let you use the SyncLock on generic type parameters if the compiler is not certain the generic type parameter is a reference type.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.