473,498 Members | 891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need tips on how to program this!

IDE: VS .NET 2003
OS: XP pro sp2

I'm developing a server application, clients will connect to it over the net
and start different tasks....

When people sends a command to the program, the command is first placed into
ThreadPool for await processing...

Here is the what I'm having problem with:
I want to implement some kind of a timeout functionality, so if a task takes
too long to perform the user will be notified that a timeout occured on the
server... I'm not sure how to implement timeout, because I must time the
task from the server receive the task and put it into the threadpool and
await processing... while it is in the threadpool it's waiting to be
processed, and as far as I know, if a timeout happens while it's still in
the threadpool it will not be triggered because it isn't assgined processor
power...

Please give me some tips on how to implement this functionality

Jeff

Nov 17 '05 #1
4 1300
Here is one way I might do it....

When the command is recieved, the command is put into an object where the
command, the IP or other info about the sender of the command is passed into
the constructor of the object, and inside the constructor there is code to
store the time of command reception, and the other info into variables then
store it in the pool.

When its time to execute the command, get the object and check to see if it
is too old to process and if so, send a message to the sender that the
server was too busy to execute the command and to try again.

Once you are past that point, you have this command object reception time,
that you can work with to perhaps utilize some sort of user defined event
that aborts the current command and sends a message that the command has
timed out, and then dispose of the command object or whatever you wish to do
with it.

Also, on the internet, I remember something about packets already having a
built in lifetime, you might be able to utilize this functionality rather
than re-inventing the wheel.

"Jeff" <it************@hotmail.com.NOSPAM> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
IDE: VS .NET 2003
OS: XP pro sp2

I'm developing a server application, clients will connect to it over the
net and start different tasks....

When people sends a command to the program, the command is first placed
into ThreadPool for await processing...

Here is the what I'm having problem with:
I want to implement some kind of a timeout functionality, so if a task
takes too long to perform the user will be notified that a timeout occured
on the server... I'm not sure how to implement timeout, because I must
time the task from the server receive the task and put it into the
threadpool and await processing... while it is in the threadpool it's
waiting to be processed, and as far as I know, if a timeout happens while
it's still in the threadpool it will not be triggered because it isn't
assgined processor power...

Please give me some tips on how to implement this functionality

Jeff


Nov 17 '05 #2
What will be "timing out"? The job itself or timeout waiting for the job to
start (i.e. very busy). Are you saying that you want a job to only run for
max time of 10 minutes or something? Will the jobs be Batch Files or EXEs
run with the Process class or predefined Methodswith args on your server?

--
William Stacey [MVP]

"Jeff" <it************@hotmail.com.NOSPAM> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
IDE: VS .NET 2003
OS: XP pro sp2

I'm developing a server application, clients will connect to it over the
net and start different tasks....

When people sends a command to the program, the command is first placed
into ThreadPool for await processing...

Here is the what I'm having problem with:
I want to implement some kind of a timeout functionality, so if a task
takes too long to perform the user will be notified that a timeout occured
on the server... I'm not sure how to implement timeout, because I must
time the task from the server receive the task and put it into the
threadpool and await processing... while it is in the threadpool it's
waiting to be processed, and as far as I know, if a timeout happens while
it's still in the threadpool it will not be triggered because it isn't
assgined processor power...

Please give me some tips on how to implement this functionality

Jeff


Nov 17 '05 #3


Jeff wrote:
IDE: VS .NET 2003
OS: XP pro sp2

I'm developing a server application, clients will connect to it over the net
and start different tasks....
Why would you use the ThreadPool to execute the tasks? especially if you
expect them to be long-lived you should just start a new Thread().

If it is because you wish to impose a limit on the amount of running
jobs, put them in a producer-consumer Queue and use a semaphore to limit
the amount of started threads.

How are you going to "timeout"? there really is no reliable way to stop
a Thread in .NET, both Thread.Interrupt and Thread.Abort may block
indefinatly, and they both have "issues". If your jobs are started in
separate Process'es, then you can abort them when their timeout expires
by killing the process, but that may also be unacceptable to you.

You could have something like:

- a "timeout-thread", which loops:
- waits for the closest timeout to expire
- try to kill the corresponding thread/process if it's still around
- an "enqueue-thread", which loops:
- accept jobs from network
- enqueue job
- a "dequeue-thread", which loops:
- pop from the queue
- [optional: limit running jobs] wait for a semapore
- starts a new thread
- [optional: limit running jobs] a "monitor-thread", which loops:
- waits for any of the started threads to expire
- signal the semaphore
When people sends a command to the program, the command is first placed into
ThreadPool for await processing...
Don't use the ThreadPool for running longer jobs, it's a resource which
others might use. Use a new Thread or Process, which *fails* instead of
*blocking* if that resource (Threads, Processess) is exhausted.
task from the server receive the task and put it into the threadpool and
To monitor the complete time from accept to execution, you need to
time-stamp the incoming jobs when they are received. You also need to
traverse the Queue at regular intervals, expiring jobs that are
time-out'et before they have even begun.
Please give me some tips on how to implement this functionality


Thats my $.02

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #4

When the command is recieved, the command is put into an object where the
command, the IP or other info about the sender of the command is passed
into the constructor of the object, and inside the constructor there is
code to store the time of command reception, and the other info into
variables then store it in the pool.

When its time to execute the command, get the object and check to see if
it is too old to process
But that might still be way after the timeout value has expired ... wouldn't
it be better to have the queuing object itself have a timer and when it runs
out, remove itself from the queue and return timeout failure return code to
the client? Or alternatively a 'timeout-checking' thread.

and if so, send a message to the sender that the server was too busy to
execute the command and to try again.

Once you are past that point, you have this command object reception
time, that you can work with to perhaps utilize some sort of user defined
event that aborts the current command and sends a message that the command
has timed out, and then dispose of the command object or whatever you wish
to do with it.

Also, on the internet, I remember something about packets already having a
built in lifetime, you might be able to utilize this functionality rather
than re-inventing the wheel.

"Jeff" <it************@hotmail.com.NOSPAM> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
IDE: VS .NET 2003
OS: XP pro sp2

I'm developing a server application, clients will connect to it over the
net and start different tasks....

When people sends a command to the program, the command is first placed
into ThreadPool for await processing...

Here is the what I'm having problem with:
I want to implement some kind of a timeout functionality, so if a task
takes too long to perform the user will be notified that a timeout
occured on the server... I'm not sure how to implement timeout, because I
must time the task from the server receive the task and put it into the
threadpool and await processing... while it is in the threadpool it's
waiting to be processed, and as far as I know, if a timeout happens while
it's still in the threadpool it will not be triggered because it isn't
assgined processor power...

Please give me some tips on how to implement this functionality

Jeff



Nov 17 '05 #5

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

Similar topics

13
2176
by: Chris Mantoulidis | last post by:
There must be some tips to make a program quicker. I guess more than 50% of ppl here will say "avoid the if-s". Yeah I know this makes a program quicker but some times an "if" is inevitable,...
34
18200
by: John Harrison | last post by:
An odd confession; an odd request; but here's the tale.... My company has a few PC systems which we have used for about 7 years and not updated - we've "made do", and besides, "if it ain't...
9
1693
by: Lauren Wilson | last post by:
Hi Folks, We've been using Crypto ++32 to control licensed access to our widely distributed Access 2K app. Unfortunately, Sampson Multimedia appears to be out of business. Does anyone out...
2
2197
by: alan | last post by:
Hi all, I have create a simple function and make a pure C dll. When I use this DLL from my main program, I found I cannot see this function's definition tips (yellow box). It works fine, but no...
3
1382
by: Square eyes | last post by:
Hi, I'm working on a program which scans .Net programs and gives hints and tips. At the moment, it can spell check forms, reports and code and some hints might include something like...
28
3287
by: Yuri CHUANG | last post by:
"No newline at the end of your output" is really a problem? I've never learned that before. So I desire to know some tips about writting a program perfectly.Can anyone give me some tips which are...
1
1753
by: larpup | last post by:
I have a A2000 mdb and it is missing Microsoft Outlook 9.0 library.... I see that it is not listed. How can I get this into my references? Lar
21
2509
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
4
14650
by: sathyancse | last post by:
Hi, i found the new method of find cube root of the given value.i want to implement in the c++ program.ex: if you give the answer the certain value i find the cube value.(i.e)if you give the...
0
7124
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
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.