From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
New lock type and semantics
From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development
New lock type and semantics
- [Instructor] C# 13 changed how locking can work with a new type, System.Threading.Lock. Even so, the current lock syntax will work as it did before C# 13, so any of your current lock code will still work. Instead, the motivation for the new type was to give us more control over the existing monitor-based lock keyword and slightly better performance. If you get the start code for this video, there is a new view model called LockingViewModel that uses the old lock syntax. So we're going to open this up. And look at the variable called _Lock. As you can see, locks have been done against simple object types before. And if we're going to scroll down here to the CountLocked method, here we can see using that _Lock keyword. The syntax for monitor-based locks were pretty simple. It will lock out a section of code. The same lock could even be used for multiple sections of code, keeping competing threads out of different sections of code that all use the same resources. So let's see how this…
Contents
-
-
-
-
-
-
(Locked)
Params collections4m 6s
-
(Locked)
New lock type and semantics3m 53s
-
(Locked)
New escape sequence: \e1m 48s
-
(Locked)
Method group natural type improvements4m 18s
-
(Locked)
Implicit indexer access in object initializers2m 49s
-
(Locked)
Enable ref locals and unsafe contexts in iterators and async methods3m 55s
-
(Locked)
Enable ref struct types to implement interfaces4m 43s
-
(Locked)
Allow ref struct types as arguments for type parameters in generics5m 50s
-
(Locked)
Partial properties and indexers6m 21s
-
(Locked)
Overload resolution priority4m 4s
-
(Locked)
-
-