Java-like synchronized methods in C#

To prevent Threads using a method at the same time and messing things up Java programmers usually use the synchronized statement when declaring a method.

In the C# world lock-blocks can be used to archieve similar effects. But putting a whole function into a block looks nasty, another way is to use this method decorator:


Please note, that System.Runtime.CompilerServices must be imported first.

0 Responses to “Java-like synchronized methods in C#”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: