Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Running a function in the background (http://www.velocityreviews.com/forums/t487173-running-a-function-in-the-background.html)

ADT_CLONE 03-26-2007 06:10 AM

Running a function in the background
 
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.


=?iso-8859-1?q?Erik_Wikstr=F6m?= 03-26-2007 06:20 AM

Re: Running a function in the background
 
On 26 Mar, 08:10, "ADT_CLONE" <spell_d...@hotmail.com> wrote:
> 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.


Threads is the (only?) way to go. Ask again in
microsoft.public.dotnet.languages.vc and they will be able to help you
with that. Perhaps they can also tell you a way to avoid using a loop
in waitForClient() if you describe what it does.

--
Erik Wikström


Alexander Block 03-26-2007 08:31 AM

Re: Running a function in the background
 
On 26 Mrz., 08:20, "Erik Wikström" <eri...@student.chalmers.se> wrote:
> On 26 Mar, 08:10, "ADT_CLONE" <spell_d...@hotmail.com> wrote:
>
> > 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.

>
> Threads is the (only?) way to go. Ask again in
> microsoft.public.dotnet.languages.vc and they will be able to help you
> with that. Perhaps they can also tell you a way to avoid using a loop
> in waitForClient() if you describe what it does.
>
> --
> Erik Wikström


There's also a way to handle sockets in asynchronous mode. You should
read through the MSDN documentation to find out how to use them on
Windows. Look for WSAAsyncSelect, which sends Windows messages to your
application has pending incoming data or connections.


exylum 03-26-2007 09:44 AM

Re: Running a function in the background
 
also check the winapi settimer function:
http://msdn.microsoft.com/library/de...s/settimer.asp

although i think that the asynchronous mode posted by
Alexander Block is the best way.


ADT_CLONE 03-26-2007 09:47 AM

Re: Running a function in the background
 
On Mar 26, 7:44 pm, "exylum" <exy...@gmail.com> wrote:
> also check the winapi settimer function:http://msdn.microsoft.com/library/de...ary/en-us/winu...
>
> although i think that the asynchronous mode posted by
> Alexander Block is the best way.



Thanks guys, I'll look through these.



All times are GMT. The time now is 11:08 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.