473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Mar 26 '07 #1
6 1309
>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
Mar 26 '07 #2
On Mar 26, 5:25 pm, David Lowndes <Dav...@example.invalidwrote:
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

Is it possible for you to explain where abouts I could find tutorials/
resources about this? Thanks.

Mar 26 '07 #3
>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


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
Mar 26 '07 #4
On Mar 26, 7:37 pm, David Lowndes <Dav...@example.invalidwrote:
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
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.

Mar 26 '07 #5
>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
Mar 26 '07 #6

"ADT_CLONE" <sp********@hotmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
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.

Mar 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Arun | last post by:
Hi, This is a scripting question, but since I am writing the script in python I am posting this question here: I have a python script that runs a simulator (that was written in c++, so I use...
29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
5
by: Ben Dewey | last post by:
This is a repost, But I have some new information. I have a server that is configured for .NET 1.1 and 2.0. For some reason all my postback events for aren't firing when using .NET 1.1. Under...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
2
by: Dave Hughes | last post by:
Just noticed something rather annoying after upgrading my test box (a Linux server running DB2 UDB v8 for LUW) to fixpak 11 (for reference it was previously on fixpak 7). In the past I've relied...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
4
by: ADT_CLONE | last post by:
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...
3
by: nathanwb | last post by:
I have the following php code, at the top I am pulling a piece of data from a query and I echo the results with no problem, I am using Ajax with this page as well and further down the page when I...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.