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.
David Lowndes - 26 Mar 2007 08:25 GMT
>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
ADT_CLONE - 26 Mar 2007 08:36 GMT
> >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
[quoted text clipped - 4 lines]
>
> Dave
Is it possible for you to explain where abouts I could find tutorials/
resources about this? Thanks.
David Lowndes - 26 Mar 2007 09:43 GMT
>> >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
[quoted text clipped - 7 lines]
>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
ADT_CLONE - 26 Mar 2007 10:03 GMT
> >> >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
[quoted text clipped - 14 lines]
>
> 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.
David Lowndes - 26 Mar 2007 11:01 GMT
>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
Ben Voigt - 28 Mar 2007 20:58 GMT
> Hello guys,
>
[quoted text clipped - 9 lines]
> 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.