Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2007

Tip: Looking for answers? Try searching our database.

Running a function in the background

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ADT_CLONE - 26 Mar 2007 07:52 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.