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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:32:30+00:00 2026-05-12T19:32:30+00:00

can somebody tell me why my code is not working? class Connection { public

  • 0

can somebody tell me why my code is not working?

class Connection
{
    public static StreamWriter writer;
    public static string SERVER;
    private static int PORT;
    private static string USER;
    private static string NICK;
    private static string CHANNELS;
    private Thread connection;
    private Thread ping;
    public Connection()
    {
        connection = new Thread(new ThreadStart(this.Run));
        ping = new Thread(new ThreadStart(this.Ping));
    }
    public void Start(string server, int port, string ident, string realname, string nick, string channels)
    {
        SERVER = server;
        PORT = port;
        USER = "USER " + ident + " 8 * :" + realname;
        NICK = nick;
        CHANNELS = channels;
        connection.Start();
    }
    public void Ping()
    {
        while (true)
        {
            try
            {
                Connection.writer.WriteLine("PING :" + SERVER);
                Connection.writer.Flush();
                Thread.Sleep(15000);
            }
            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
    }
    public void Run()
    {
        NetworkStream stream;
        TcpClient irc;
        string inputLine;
        StreamReader reader;
        try
        {
            irc = new TcpClient(SERVER, PORT);
            stream = irc.GetStream();
            reader = new StreamReader(stream);
            writer = new StreamWriter(stream);
            writer.WriteLine(USER);
            writer.Flush();
            writer.WriteLine("NICK " + NICK);
            writer.Flush();
            Thread.Sleep(5000);
            writer.WriteLine("JOIN " + CHANNELS);
            writer.Flush();
            while (true)
            {
                while ((inputLine = reader.ReadLine()) != null)
                {
                    Console.WriteLine(inputLine);
                }
                writer.Close();
                reader.Close();
                irc.Close();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            Thread.Sleep(5000);
            Run();
        }
    }
}

It connects to the server fine, but the ping Thread and voids seem to not functioning at all! and i dont know why, everything seems correct unless im missing something very obviousC

  • 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-12T19:32:30+00:00Added an answer on May 12, 2026 at 7:32 pm

    You haven’t started your ping thread. Call Start method of it.

    Another note – don’t use Thread.Sleep for threads/process synchronization. From my experience, code using it is usually slow, unreliable and hard to maintain. Use Monitor class or various WaitHandle implementations (e.g. AutoResetEvent) or whatever. For client/server communication try to wait until server response to your request (if such is defined in protocol), not just timeout.

    Also, if you are starting new threads either make this threads stop (e.g. in Dispose method of your class) or set IsBackground property, or, preferrably, both. Otherwise these threads will block your process from stopping.

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

Sidebar

Related Questions

can somebody tell me what is wrong? JS Code $.ajax({ url:http://www.google.com/complete/search?qu=chicken, success:function(data){ var test_data
can somebody tell me does my conversation from c to delphi is well: c
I am facing problem with hibernate annotations.For the code shown below I have a
I have a code like this : <script type=text/javascript> var currentPicture;//default picture var picEL;//the
I want to create a class in c++. This class must manage with a
I found a code snippet on http://www.41latitude.com/post/1268734799/google-styled-maps : [ { featureType: administrative, elementType: labels,
From the picture above, I would conclude that Java EE 6 architecture is an
First of all I'm a total newby in visual basic, I needed to hack
I'm writing an ATL project and I wonder how should I create classes here.
I'm trying to read all the contacts using RawContacts.entityIterator but I'm seeing this error:

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.