Valhalla Legends Forums Archive | Visual Basic Programming | Console application

AuthorMessageTime
BreW
So i made this console application and in order for the program to stay active, i have to run a constant loop.
this is VERY cpu consuming, and when I tried to connect to bnet with it, it took about 7-8 seconds. (if i commented out the loop it would connect much faster, but not work after that.)

Private Const STD_INPUT_HANDLE = -10&
Private Const STD_OUTPUT_HANDLE = -11&
Private Const STD_ERROR_HANDLE = -12&

Sub Main()
    Show
    Do
        DoEvents
        Select Case ReadText
            Case "/exit": Hide
            Case "/connect"
                frmMain.WS.Close
                frmMain.WS.Connect "213.248.106.200", 6112
                AddChat vbForeYellow, "[BNET] Connecting..."
        End Select
        DoEvents
    Loop
End Sub

Public Sub Show()
    AllocConsole
    SetConsoleTitle "Console Test"
    hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)
End Sub

so on...

Anyone got any ideas
April 14, 2007, 1:29 AM
warz
C
April 14, 2007, 1:33 AM
Barabajagal
Don't use VB for console apps?
April 14, 2007, 1:35 AM
BreW
but... i like vb
April 14, 2007, 1:36 AM
warz
but... what you're trying to write is better suited for a different language
April 14, 2007, 1:42 AM
BreW
acually you're right... the past two topics i've posted here pertains to things almost unheard of in vb6 and easy as hell in c/c++, but i still love vb if vb was a person i'd hug it
Uhh and btw i believe the way consoles in C work the same way, except they have a break(); (or something) at the end of execution, so it doesn't exit until it receives input (a key press) So i think the entire thread is paused in C, too. You just don't notice it. (correct me if im completely wrong) Yeah, using a console was a bad idea. Anyone know where I can get the "raster fonts" that console uses?
April 14, 2007, 1:46 AM
l2k-Shadow
instead, you could use CreateWindow() and code the application window, then implement a callback function
April 14, 2007, 2:47 AM
BreW
[quote author=l2k-Shadow link=topic=16614.msg167934#msg167934 date=1176518850]
instead, you could use CreateWindow() and code the application window, then implement a callback function
[/quote]
I acually tried that-- by using form_Load on startup, then calling sub main(). Now it no longer exits immediately, but the console window that is "spawned" is now "inactive" (no input/output). It seems like I no longer have a handle on that console window (but i know i do, i would have to. I don't call freeconsole() until hide, which is only called upon exit command)
April 14, 2007, 3:41 AM
l2k-Shadow
is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
April 14, 2007, 4:23 AM
Hell-Lord
One thing is to remove DoEvents.
April 14, 2007, 6:08 AM
warz
one thing one thing one thing, boo hoo
April 14, 2007, 6:52 AM
Hell-Lord
[quote author=♥ link=topic=16614.msg167939#msg167939 date=1176533533]
one thing one thing one thing, boo hoo
[/quote]

???
April 14, 2007, 9:01 AM
BreW
[quote author=Hell-Lord link=topic=16614.msg167938#msg167938 date=1176530881]
One thing is to remove DoEvents.
[/quote]
ok, please you try that
April 14, 2007, 3:49 PM
BreW
[quote author=l2k-Shadow link=topic=16614.msg167936#msg167936 date=1176524601]
is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
[/quote]
Wow, i just tried the sleep api like you said and it worked absolutely perfect. (although i'm not exactly sure why/how) Thanks, shadow.

Edit*
It doesn't work after you enter text 3 times. And if I use the loop way, which is guarenteed to work, it doesn't connect. What gives -_-
April 14, 2007, 3:49 PM
Myndfyr
[quote author=brew link=topic=16614.msg167931#msg167931 date=1176514571]
but... i like vb
[/quote]

VB.NET.  Console.ReadLine() blocks the thread while in a loop preventing massive CPU usage.
April 16, 2007, 7:01 AM
Imperceptus
i strongly suggest not making a console app in vb. its really not going to perform like you would want it to. you can do everything you would want to in vb.net.  beyond which. Is a console bot what you really want to do?
April 18, 2007, 11:32 PM

Search