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 9295019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:30:19+00:00 2026-06-18T21:30:19+00:00

internal static void ExecuteCommand(NLO nlo) { switch (nlo.action) { //synchronize each method in case

  • 0
internal static void ExecuteCommand(NLO nlo)
{
    switch (nlo.action)
    {
        //synchronize each method in case
        case (NLO.Actions.SET):
            swSet(nlo);
            break;
        case (NLO.Actions.ADD):
            swAdd(nlo);
            break;
        default:
            throw new System.Exception("Error");
            //break;
    }
    return;
}

i want to lock so each of the methods swSet and swAdd are able to run in paralell, but lock swSet from running in concurrent with itself and same for swAdd

Is the easiest way to put locks around each case or to have the lock in the methods themselves or to have [MethodImpl(MethodImplOptions.Synchronized)]
on the method?

Will the last solution lock all methods?

  • 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-18T21:30:20+00:00Added an answer on June 18, 2026 at 9:30 pm

    [MethodImpl(MethodImplOptions.Synchronized)] is not overly documented, but will generally use the same lock object for all such methods in the same type; from MSDN:

    Only one thread can execute in any of the instance functions, and only one thread can execute in any of a class’s static functions.

    Frankly I never find that attribute useful. In your case, it sounds like you need separate locking for the two methods:

    private static readonly object setLock = new object(), addLock = new object();
    
    static void swAdd(...) {
        lock(addLock) {...}
    }
    static void swSet(...) {
        lock(setLock) {...}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method: internal static void AssignNewArrayItem(ref Xml.CLASSNAME[] Items, Xml.CLASSNAME Item) { if
Here is the code: internal static void UpdateErrorLogTable(string type, string location, string method, Exception
I wrote a method Assert(): [System.Diagnostics.Conditional(DEBUG)] internal static void Assert(bool condition) { if (!condition)
I have simplified my code to this internal class Program { private static void
class Program { internal delegate int CallBack(int i); static void Main(string[] args) { CallBack
I have a method to Generate Expression By Clause as below: internal static Expression<Func<TModel,
I have this code... internal static void Start() { TcpListener listenerSocket = new TcpListener(IPAddress.Any,
Code using System; internal static class Test { private static void Main() { try
class Debug { internal static void Assert(bool condition) { #if DEBUG Log.Out(Asserted); #endif }
I have the following code: namespace ConectorV2 { [assembly:InternalsVisibleTo(Pruebas)] internal static class Utilidades {

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.