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

  • Home
  • SEARCH
  • 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 3440042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:23:05+00:00 2026-05-18T08:23:05+00:00

I strongly suspect I shouldn’t be using a static factory method here, but for

  • 0

I strongly suspect I shouldn’t be using a static factory method here, but for the mean time I am at a loss how to implement this. The following code gives a compile error on the line in CreateOpenPort that assigns _currentPort_DataReceived because that delegate method isn’t static. How can I resolve this, preferably using a non-static factory method?

    public static SerialPortService CreateOpenPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
    {
        var service = new SerialPortService
                          {
                              _currentPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits)
                          };
        service._currentPort.DataReceived += CurrentPortCharsReceived;
        service._currentPort.Open();
        return service;
    }

void CurrentPortCharsReceived(object sender, SerialDataReceivedEventArgs e)
{
    var port = (SerialPort) sender;

    var chars = new char[port.BytesToRead];
    var x = port.Read(chars, 0, chars.Length);
    OnDataReceived(chars.ToString());
} 
  • 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-05-18T08:23:06+00:00Added an answer on May 18, 2026 at 8:23 am

    Hmm, static factory with a static handler is not so bad an idea although I will try avoiding them for the sake of unit tests.

    Implement a singleton pattern if there is going it be only one instance in the AppDomain. That will be clean and working.

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

Sidebar

Related Questions

I'm trying to create a web service using Azure. For the time being, everything
I am using QtService to write a web page thumbnail rendering service. Is it
In C# Dictionary<String, String> dictionary = new Dictionary<String, String>(); In Java, this errors with
I'm trying to generate KML using Builder. I know their are some options out
I'm using Materialized Path tree (provided by django-treebeard) to create a tree structure (
I've got a multithreaded app using the OmniThreadLibrary . I am misusing the OTL
The DataContext.GetTable() method will return an object of type: System.Data.Linq.Table By doing that, I
I strongly need to override JSF 2.0 Content-Type header. Default it is Content-Type:application/xhtml+xml; charset=UTF-8
There seems to be an issue with the ViewBag dynamic properties. Lets say I

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.