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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:51:12+00:00 2026-05-28T04:51:12+00:00

I ask similar question here I use this sample to implement namedpipes in win

  • 0

I ask similar question here I use this sample to implement namedpipes in win form, but now I need to run that in console application so there is a problem in handle events, in original code some events declared and fired in some threads as following:

public class PipeServer {

  public delegate void MessageReceivedHandler(byte[] message)

  public event MessageReceivedHandler MessageReceived;


  void ListenForClients() {

    //Some code

    Thread readThread = new Thread(Read) { IsBackground = true  };

  }

  void Read(object clientObj) {

    //Some Code

    if(MessageReceived != null)
        MessageReceived(ms.ToArray());

  }

}

So in win form we use it like this:

public partial class Form1 : Form {

private PipeServer pipeServer = new PipeServer();

public Form1(){

pipeServer.MessageReceived += pipeServer_MessageReceived;

}

void pipeServer_MessageReceived(byte[] message) {

Invoke(new PipeServer.MessageReceivedHandler(Do_pipeServer_MessageReceived),
       new object[] { message });
}

public void Do_pipeServer_MessageReceived(byte[] message ) {

//Do Job

}

So when I use Console Application I can’t use Invoke, Does any one know what is the implementation for this in console apps?

  • 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-28T04:51:13+00:00Added an answer on May 28, 2026 at 4:51 am

    Finally I found that for each event that fired in PipeServer class I remove that event and replace with the handler (onevent) so the above example will be like the following:

    public class PipeServer {
    
    
    void ListenForClients() {
    
    //Some code
    
    Thread readThread = new Thread(Read) { IsBackground = true  };
    
    }
    
    void Read(object clientObj) {
    
    //Some Code
    
    MessageReceived(ms.ToArray());
    
     }
    
    
    void MessageReceived(byte[] message){
    
      //Do Job
    
    }
    
    
    }
    

    And added a constructor for PipeServer class for needed implementation, at the end just declare an instance of PipeServer. This approach maybe not the standard implementation but worked for me.

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

Sidebar

Related Questions

I ask similar question here but in this question I use another implementation, exactly
I ask a similar question here and Darin Dimitrov answer that we can't use
I ask similar question here , assume this type: public class Product { public
I've seen many other people ask this question here and here , but it
I have posted a question on here previously asking similar advise, but this project
I ask a similar question here . This is My Model: [DisplayName(National Code)] [Required(ErrorMessage
Related to this question here , but I decided to ask another question for
There is a question very similar to this but I wanted to ask it
I ask this question following the issue I raised here . The point is
Somebody ask me this question today . What is the need of reference in

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.