Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Member 120616008-Feb-16 0:20
Member 120616008-Feb-16 0:20 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Jochen Arndt8-Feb-16 0:34
professionalJochen Arndt8-Feb-16 0:34 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Member 120616008-Feb-16 0:38
Member 120616008-Feb-16 0:38 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Member 120616008-Feb-16 0:19
Member 120616008-Feb-16 0:19 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Jochen Arndt8-Feb-16 0:22
professionalJochen Arndt8-Feb-16 0:22 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Member 120616007-Feb-16 21:53
Member 120616007-Feb-16 21:53 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Jochen Arndt7-Feb-16 22:15
professionalJochen Arndt7-Feb-16 22:15 
GeneralRe: Is this serial port class and how I use it thred safe? Pin
Pete O'Hanlon8-Feb-16 0:13
mvePete O'Hanlon8-Feb-16 0:13 
To be honest, if I were doing this, I'd look at using a different architecture altogether because you're mixing a lot of responsibilities in your code here. What I would be tempted to go with is to have your API exposed so that you have separate writer and reader implementations, and the actual management of the port operation would be the responsibility of a completely separate class altogether. As I tend to compose objects together with IoC, I would constrain the port functionality to be container controlled so that all classes get the same instance and I would put the checking of the port along with its creation in there. I would also hide this as an internal implementation detail so you would have this as an internal interface with an internal implementation. That way, your client code only sees the separate reader and writer interfaces. Something like this internally:
C#
internal interface IHaspPort
{
  SerialPort Port { get; }
}

internal class HaspPort : IHaspPort
{
  private readonly object SyncLock = new object(); // Doesn't need to be static if I'm letting IoC serve up the same instance everytime.
  private SerialPort port;
  public SerialPort Port
  {
    get
    {
      if (port == null)
      {
        lock(SyncLock)
        {
          if (port == null)
          {
            // Do the open port stuff here...
          }
        }
      }
      return port;
    }
  }
}
Then, you simply inject this instance into your reader and writer classes and let it take care of itself.
This space for rent

GeneralRe: Is this serial port class and how I use it thred safe? Pin
Member 120616008-Feb-16 0:18
Member 120616008-Feb-16 0:18 
QuestionHave you worked directly with 'ApplicationContext in WinForms ? Pin
BillWoodruff7-Feb-16 18:07
professionalBillWoodruff7-Feb-16 18:07 
GeneralRe: Have you worked directly with 'ApplicationContext in WinForms ? Pin
Sascha Lefèvre7-Feb-16 18:56
professionalSascha Lefèvre7-Feb-16 18:56 
GeneralRe: Have you worked directly with 'ApplicationContext in WinForms ? Pin
BillWoodruff7-Feb-16 19:08
professionalBillWoodruff7-Feb-16 19:08 
GeneralRe: Have you worked directly with 'ApplicationContext in WinForms ? Pin
Sascha Lefèvre7-Feb-16 19:49
professionalSascha Lefèvre7-Feb-16 19:49 
QuestionOLEDB excel update is not working Pin
kvchennai7-Feb-16 17:11
kvchennai7-Feb-16 17:11 
General[REPOST] Pin
Sascha Lefèvre7-Feb-16 17:41
professionalSascha Lefèvre7-Feb-16 17:41 
GeneralRe: [REPOST] Pin
kvchennai7-Feb-16 18:03
kvchennai7-Feb-16 18:03 
Question(c#) if (label1.Text < label2.Text); ??? Pin
Member 104109727-Feb-16 5:47
Member 104109727-Feb-16 5:47 
AnswerRe: (c#) if (label1.Text < label2.Text); ??? Pin
OriginalGriff7-Feb-16 6:15
mveOriginalGriff7-Feb-16 6:15 
GeneralRe: (c#) if (label1.Text < label2.Text); ??? Pin
Member 104109727-Feb-16 7:08
Member 104109727-Feb-16 7:08 
AnswerRe: (c#) if (label1.Text < label2.Text); ??? Pin
Richard MacCutchan7-Feb-16 6:20
mveRichard MacCutchan7-Feb-16 6:20 
Questiontableadapter updating! Pin
Isawyouoo6-Feb-16 14:42
Isawyouoo6-Feb-16 14:42 
AnswerRe: tableadapter updating! Pin
Dave Kreskowiak6-Feb-16 16:40
mveDave Kreskowiak6-Feb-16 16:40 
GeneralRe: tableadapter updating! Pin
Isawyouoo8-Feb-16 11:33
Isawyouoo8-Feb-16 11:33 
GeneralRe: tableadapter updating! Pin
Dave Kreskowiak8-Feb-16 16:41
mveDave Kreskowiak8-Feb-16 16:41 
Questionhow can i get this to work in c# Pin
elfenliedtopfan56-Feb-16 13:52
elfenliedtopfan56-Feb-16 13:52 

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.