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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:59:48+00:00 2026-06-10T20:59:48+00:00

Recently I have started work on a multi-threaded console based application using VB.Net and

  • 0

Recently I have started work on a multi-threaded console based application using VB.Net and am having an (explainable) error. The program itself is an server that receives socket connections from outside apps in different threads. I also have a separate thread that simply waits for a user to enter text into the app using console.readline (so that server commands can be entered such as HELP or STATUS).

The problem is that the program outputs messages from the different socket threads, and if I am in the middle of typing a command, it gets broken up. If I enter the command “status”, it works as it should, but for the user entering the command, it is broken up and they may not be able to see if they are typing the command wrong. For example:

staNew client connected.
tus

I know why this is happening, but I am curious if there is a simple fix to stop this (without having to pause the other threads during input) or possibly an easier way to allow console commands to be entered that will not be moved around on additional app output.

  • 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-06-10T20:59:49+00:00Added an answer on June 10, 2026 at 8:59 pm

    I know that this issue is mostly aesthetic, but stuff like this annoys me. I hate to answer my own question, but I actually came up with a pretty decent solution for this based on some input from others. I will attach a code sample in case anyone wants to do something similar in the future. I know there are probably better ways to do this, but here’s what I did.

    Basically instead of using console.writeline from each thread, I created a new sub routine (TextOut) which has some logic behind it. I also updated my input thread to read each char into a shared string instead of using console.readline(). Here is the code:

    Private command As String = ""
    
    Private Sub ConsoleInput()
        Dim cki As ConsoleKeyInfo
        cki = Console.ReadKey()
        If cki.Key = ConsoleKey.Escape Then
            command = "" 'Clear command
        ElseIf cki.Key = ConsoleKey.Backspace Then
            If Len(command) > 0 Then 'Make sure you don't go out of bounds
                For i As Integer = 0 To Len(command)
                    Console.Write(" ") 'Clear output since new string will be shorter
                Next
                command = Left(command, Len(command) - 1) 'Shorten command by 1 char
            End If
            Console.CursorLeft = 0 'Set the cursor to the beginning of the line
            Console.Write(command) 'Write the command to the screen
        ElseIf cki.Key = ConsoleKey.Enter Then 'Command has been submitted, start checking
            Console.CursorLeft = 0 'Set the cursor to the beginning of the line
            For i As Integer = 0 To Len(command)
                Console.Write(" ") 'Clear output from command (hides the executed command)
            Next
            Dim tempCMD As String = command
            command = ""
    
            'If/then statements for validating command goes here
    
            command = "" 'Clear command to allow new input
        Else
            command += cki.KeyChar 'Add char to command string
            Console.CursorLeft = 0 'Set the cursor to the beginning of the line
            Console.Write(command) 'Write the command to the screen
        End If
        ConsoleInput() 'Loop for more input 
    End Sub
    
    
    Sub TextOut(ByVal message As String)
        If command <> "" Then
            For i As Integer = 0 To Len(command)
                Console.Write(" ") 'Clears output in case output is shorter than current command
            Next
            Console.CursorLeft = 0 'Sets cursor to beginning of row
        End If
        Console.WriteLine(message) 'Writes the current message to the screen
        If message <> command Then
            Console.Write(command) 'Writes the command back to the screen
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An application I have recently started work on has to register two dll's, because
I have recently started using RSpec for Integration testing in my Rails application, to
I've recently started using Gradle and replacing my existing Maven-based projects. I have had
I have recently started work on a large project in .net (C#) and I
I have recently started using automapper and it has work fine for me so
I have recently started applying for .Net jobs. I currently work in a sales
I have recently started using doc-view in Emacs, but I am having quite a
I have recently started work on an application that is already deployed to production.
I have recently started using CAML.NET IntelliSense for SharePoint with Visual Studio 2008; which
I have recently started having a need to start learning Java Script. My application

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.