Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8467105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:32:44+00:00 2026-06-10T15:32:44+00:00

I came across this definition of Object constructor (metadata from mscorlib.dll ) [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]

  • 0

I came across this definition of Object constructor (metadata from mscorlib.dll)

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public Object();

I didn’t understood what ConstrainedExecution (Cer.MayFail) mean can someone tell me with an example in this case.

I came across this code, also tell me if it is correct to write like this,

public class MyClass
{
    private static object instanceLock = new object();

    private void Func()
    {
        bool instanceLockTaken = false;

        Monitor.TryEnter(instanceLock, ref instanceLockTaken);
        //...
        Monitor.Exit(instanceLock);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:32:46+00:00Added an answer on June 10, 2026 at 3:32 pm

    Constrained Execution is what you’re trying to achieve by locking the thread.

    From: http://msdn.microsoft.com/en-us/magazine/cc163716.aspx

    A Cer value of MayFail is used to signal that when faced with
    asynchronous exceptions, the code may not complete in an expected
    fashion. Since thread aborts are being delayed over constrained
    execution regions, this really means that your code is doing something
    that may cause memory to be allocated or that might result in a stack
    overflow. More importantly, it means that you must take the possible
    failures into consideration when calling this method.

    In your case, because the object is static and only created once, this will not be a problem.

    Monitor.TryEnter returns immediately even if a lock was not acquired. It has a boolean value, which you’re not checking, something like this would work:

    Monitor.TryEnter(instanceLock, ref instanceLockTaken);
    
      if (instanceLockTaken) 
      {
        // Do stuff here
    
        Monitor.Exit(instanceLock);
      }
    

    However, this code would mean that the if {} block would not be executed every time, if you want to acquire a lock on every thread, you’ll need to do something like this:

    lock(instanceLock)
    {
      // Do stuff here
    }
    

    This means that only a single thread can run the contents of the lock {} statement at a time, and the contents of the lock statement will be executed every time.

    On a side note, you can also make the object you’re locking readonly:

    private static readonly object instanceLock = new object();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this term in the android documentation with the accompanying definition These
I came across this situation while migrating our DB from Foxpro to SQL. Below
i came across this definition Aggregation has two properties: antisymmetry, transitivity What does it
I was browsing some code and I came across this macro definition #define D(x)
I was reading this article and I came across the following definition (in qglobal.h
I was looking for the definition of seq and came across this weirdness. Why
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
I came across this Linq to Sql code in an application I am maintaining:
I came across this due to a bug in my code and I'm curious
I came across this problem when I want to check what I input is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.