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
C
Don't use VB for console apps?
but... i like vb
but... what you're trying to write is better suited for a different language
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?
instead, you could use CreateWindow() and code the application window, then implement a callback function
Quote from: l2k-Shadow on April 13, 2007, 09:47 PM
instead, you could use CreateWindow() and code the application window, then implement a callback function
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)
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.
One thing is to remove DoEvents.
one thing one thing one thing, boo hoo
Quote from: ♥ on April 14, 2007, 01:52 AM
one thing one thing one thing, boo hoo
???
Quote from: Hell-Lord on April 14, 2007, 01:08 AM
One thing is to remove DoEvents.
ok, please you try that
Quote from: l2k-Shadow on April 13, 2007, 11:23 PM
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.
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 -_-
Quote from: brew on April 13, 2007, 08:36 PM
but... i like vb
VB.NET. Console.ReadLine() blocks the thread while in a loop preventing massive CPU usage.
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?