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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:25:03+00:00 2026-05-26T19:25:03+00:00

When I use F11 debug, NetStatus value is true , but when I use

  • 0

When I use F11 debug, NetStatus value is true, but when I use F5 debug, NetStatus value is false. Why? How do I fix it?

I don’t know what time the _connect value changes.
Is this a multi-threading synchronization issue?

namespace conn
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;

    class Program
    {
        static void Main(string[] args)
        {
            wait_conn();
        }

        private static void wait_conn()
        {
            bool NetStatus = false;
            string DataS = "127.0.0.1";

            CheckIpConn conn = new CheckIpConn();
            conn.CheckIp(DataS);

            //Thread.Sleep(3000);
            NetStatus = conn.Connected;

            if (!NetStatus)
                Console.WriteLine(conn.Connected.ToString());

            Console.Read();
        }
    }

    public class CheckIpConn
    {
        private int _port = 135;
        private volatile bool _connect;
        private IPEndPoint _iPEndPoint;
        private TcpClient _client;
        private TimerCallback _timerCallBack;
        private System.Threading.Timer _timer;

        public bool Connected
        {
            get { return _connect; }
        }

        public void CheckIp(string Ip)
        {
            _iPEndPoint = new IPEndPoint(IPAddress.Parse(Ip), _port);
            _timerCallBack = new TimerCallback(CheckConnect);
            _timer = new System.Threading.Timer(_timerCallBack, null, 10, 1000);
            _timer.Dispose();
        }

        public void CheckConnect(object o)
        {
            try
            {
                _client = new TcpClient();
                _client.Connect(_iPEndPoint);
                _connect = true;
                _client.Close();
            }
            catch
            {
                _connect = false;
            }
        }
    }
}
  • 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-26T19:25:03+00:00Added an answer on May 26, 2026 at 7:25 pm

    Your code is extremely unclear – it looks like you’re trying to do things asynchronously, but doing so badly. For example, you’re creating a Timer and then immediately disposing of it.

    When stepping line by line in the debugger, that may work – because the timer may get to fire before the Dispose call… but when you just run the code, you’re disposing of the timer before it gets a chance to fire. Additionally, you’re using the value of conn.Connected immediately after calling CheckIp – so if the timer did fire, it would probably be after you’d checked the value anyway.

    I would strongly advise you to just do the check synchronously. Get that working and then consider an asynchronous approach.

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

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
I realise that there are many existing questions regarding this issue, but I haven't
I apologize if this is a duplicate post, but I couldn't find the answer
I just read this question: Full Screen Page by pressing button instead of F11
How do F10 and F11 work in Asp.net framework. How do I use them?
I would like to know which keys (or keystrokes) would you use to replace
Use AES/Rijndael or any symmetric encryption. Encrypt the hidden value using itself as the
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
Use case: we have some project meta-data files which we want tracked, but are
Ctrl + F11 is the Run keyboard shortcut in Eclipse. But for me, that

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.