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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:43:26+00:00 2026-05-22T02:43:26+00:00

I have a Windows Forms application at the moment, and I want to create

  • 0

I have a Windows Forms application at the moment, and I want to create a new thread and run a method on another class that accepts an input.

For example

public partial class Form1: Form {
    SerialPort serialInput;
    // I want to create a new thread that will pass the parameter serialInput into the method
    // SMSListener on another class and run the method contionously on the background.
}

class SMS
{
    public void SMSListener(SerialPort serial1)
    {
        serial1.DataReceived += port_DataRecieved;
    }

    private void port_DataRecieved(object sender, SerialDataReceivedEventArgs e)
    {
        // Other codes
    }
}

How do I perform this in C#? I have seen numerous examples on the web, and most of them run the method on the same class with no parameters, but none that suits my requirements.

  • 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-22T02:43:27+00:00Added an answer on May 22, 2026 at 2:43 am

    I am not an expert on Multithreading but to the best of my knowledge you can only start threads on methods that accept an object parameter and return void. So in order to achieve that for your problem (don’t shoot me down if there is a better approach!) I would do something like

    public partial class Form1: Form {
        SerialPort serialInput;
        // I want to create a new thread that will pass the parameter serialInput into the method
        // SMSListener on another class and run the method contionously on the background.
        SMS sms = new SMS();
        Thread t = new Thread(sms.SMSListenerUntyped);
        t.Start(serialInput);
    }
    
    class SMS
    {
        public void SMSListenerUntyped(object serial1) {
            if (serial1 is SerialPort) //Check if the parameter is correctly typed.
                 this.SMSListener(serial1 as SerialPort);
            else
               throw new ArgumentException();
        }
    
        public void SMSListener(SerialPort serial1)
        {
            serial1.DataReceived += port_DataRecieved;
        }
    
        private void port_DataRecieved(object sender, SerialDataReceivedEventArgs e)
        {
            // Other code.
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows forms application that reads and updates an XML file with
I have a Windows Forms application that on it I have a RichTextBox, like
I have a Windows Forms application that uses some Application.Idle handlers to change the
Scenario I have a windows forms application. I want to use two different WCF
If you have a windows service and a windows forms application that uses the
I have windows forms application with multiple forms and controls in them. I want
I have a Windows Forms application that I need to write to the output
I want to create a windows form application that will sit on our local
I have a windows forms application that uses excel to generate some reports. Untill
I have an MDI Windows Forms application (.net 2008) that allows the user to

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.