Running a function in the background

  • Thread starter Thread starter ADT_CLONE
  • Start date Start date
A

ADT_CLONE

Hello guys,

Right now I have run into a problem. In my windows application I wish
to run a function called waitForClient(), which waits for a clients
connection using WinSock. Anyway, within the button click event, I
have inserted this function. The only problem is that when you click
the button, it freezes the whole windows application. This is because
it is running an infinite loop and isn't properly running the rest of
the button code.

What I was wondering was if there was anyway to run a function in the
background. I'm looking for an easy way out of this, though if I have
to I will use threads. Thanks in advance.
 
What I was wondering was if there was anyway to run a function in the
background. I'm looking for an easy way out of this, though if I have
to I will use threads.

A worker thread is the correct way to go. It'll be less trouble to do
it properly in the long run.

Dave
 
A worker thread is the correct way to go. It'll be less trouble to do
it properly in the long run.

Dave


Is it possible for you to explain where abouts I could find tutorials/
resources about this? Thanks.
 
There are thousands of references I wouldn't know where to point you
to first. It depends where our lack of knowledge is and what API
you're using (native or managed). Try typing "threading" into the MSDN
index for starters.

Dave


Oh ok, thanks. I'm pretty sure I'm using a native API. I've only just
started to work with the Windows API.
 
What I was wondering was if there was anyway to run a function in the
Is it possible for you to explain where abouts I could find tutorials/
resources about this? Thanks.

There are thousands of references I wouldn't know where to point you
to first. It depends where our lack of knowledge is and what API
you're using (native or managed). Try typing "threading" into the MSDN
index for starters.

Dave
 
Oh ok, thanks. I'm pretty sure I'm using a native API. I've only just
started to work with the Windows API.

In that case, the core function you probably ought to use is the 'C'
run-time function _beginthreadex() - so I'd search for samples that
involve that.

Dave
 
ADT_CLONE said:
Hello guys,

Right now I have run into a problem. In my windows application I wish
to run a function called waitForClient(), which waits for a clients
connection using WinSock. Anyway, within the button click event, I
have inserted this function. The only problem is that when you click
the button, it freezes the whole windows application. This is because
it is running an infinite loop and isn't properly running the rest of
the button code.

What I was wondering was if there was anyway to run a function in the
background. I'm looking for an easy way out of this, though if I have
to I will use threads. Thanks in advance.

A thread is indeed the way to run an arbitrary function in the background
without blocking your gui. However, what you want to do is listen for
client connections in the background, which is an altogether simpler
requirement. WSAAsyncSelect will arrange for a notication message to be
sent to your window when a client connects, so you can use event-driven code
for sockets just as you do for gui buttons and menus.
 
Back
Top