Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: ocr experts Pin
OriginalGriff31-Oct-15 2:49
mveOriginalGriff31-Oct-15 2:49 
GeneralRe: ocr experts Pin
iqballll31-Oct-15 2:51
iqballll31-Oct-15 2:51 
QuestionLooking for a solution for combine WebService and jQuery (web app) Pin
goldsoft30-Oct-15 23:29
goldsoft30-Oct-15 23:29 
Answer[REPOST] Looking for a solution for combine WebService and jQuery (web app) Pin
Richard Deeming2-Nov-15 1:57
mveRichard Deeming2-Nov-15 1:57 
Questionwhy I can't install SQL Server Compact Database for SQL Server Management Studio ? Pin
Member 245846730-Oct-15 18:17
Member 245846730-Oct-15 18:17 
AnswerRe: why I can't install SQL Server Compact Database for SQL Server Management Studio ? Pin
John Torjo31-Oct-15 0:30
professionalJohn Torjo31-Oct-15 0:30 
AnswerRe: why I can't install SQL Server Compact Database for SQL Server Management Studio ? Pin
Eddy Vluggen31-Oct-15 1:21
professionalEddy Vluggen31-Oct-15 1:21 
QuestionTrying to design thread safe class Pin
Member 1206160030-Oct-15 10:18
Member 1206160030-Oct-15 10:18 
I am somewhat beginning with threads, and I am wondering if following class is thread safe? Or in which cases it is thread safe? The idea is users should be able to initialize this class once, second time initialization should not work if deinitialization was not called. But getting the properties should give correct results... and here I am having hard time to determine in which case those properties will get correct results, and if init and deinit methods are thread safe, as well as isInited method. Help appreciated. I tried make it immutable also.

C#
static class Parameters
{
  private static int x1; // only getters of x1 and x2 will be visible to outside world
  private static int x2;  
  private static bool isInit;
  private static readonly object Locker = new object();

  public static bool isInited()
  {
   lock(Locker)
    {
    return isInit;
    }
  }

  public static int X1()
  {
    if(!isInited()) throw new Exception("init first");
    return x1;
     
  }

  public static int X2()
  {
    lock(Locker)
    {
     if(!isInited()) throw new Exception("init first");
     return x2;
    }
    
  }

  public static void init(int x, int y)
  {
    lock(Locker)
    {
      if(isInit) return;
      isInit = true;
      x1 = x;
      x2 = y; 
    }
  }

  public static void Deinit()
  {

    lock(Locker)
    {
      if(!isInit) return;
      isInit = false;
      x1 = 0;
      x2 = 0;
    }
  }


}


Or the client - user of this class has to take additional means to ensure this class is used in thread safe manner? Feedback appreciated

modified 30-Oct-15 16:23pm.

AnswerRe: Trying to design thread safe class Pin
BillWoodruff30-Oct-15 10:29
professionalBillWoodruff30-Oct-15 10:29 
GeneralRe: Trying to design thread safe class Pin
Member 1206160030-Oct-15 10:33
Member 1206160030-Oct-15 10:33 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 0:29
professionalJohn Torjo31-Oct-15 0:29 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 0:43
Member 1206160031-Oct-15 0:43 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 7:40
professionalJohn Torjo31-Oct-15 7:40 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 7:56
Member 1206160031-Oct-15 7:56 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 7:57
professionalJohn Torjo31-Oct-15 7:57 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 7:58
Member 1206160031-Oct-15 7:58 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 9:40
professionalJohn Torjo31-Oct-15 9:40 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 9:47
Member 1206160031-Oct-15 9:47 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 9:51
professionalJohn Torjo31-Oct-15 9:51 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 10:24
Member 1206160031-Oct-15 10:24 
GeneralRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 11:10
professionalJohn Torjo31-Oct-15 11:10 
GeneralRe: Trying to design thread safe class Pin
Member 1206160031-Oct-15 14:25
Member 1206160031-Oct-15 14:25 
AnswerRe: Trying to design thread safe class Pin
John Torjo31-Oct-15 23:26
professionalJohn Torjo31-Oct-15 23:26 
GeneralRe: Trying to design thread safe class Pin
Member 120616001-Nov-15 0:23
Member 120616001-Nov-15 0:23 
GeneralRe: Trying to design thread safe class Pin
John Torjo1-Nov-15 2:21
professionalJohn Torjo1-Nov-15 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.