473,372 Members | 1,039 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,372 software developers and data experts.

recursive function causing service to stall at start up

Hi,

I have the following:

public static void RunBatch() {

if (OnDemandRunning) {
//If OnDemand is Running we will do nothing
}
else{

BatchDirectoryName = "C:\\BatchQ";
String[] BatchDirectory =
Directory.GetFiles(BatchDirectoryName,"*.xml");

for (int counter = 0; counter < BatchDirectory.Length;
counter++) {
///<remarks>
/// need to break if an OnDemand event happens.
///</remarks>
///
//TODO: Implement actual event handling etc. instead of
the fake event handling doing now.
if (OnDemandRunning) { break; }
String BatchFile =
BatchDirectory.GetValue(counter).ToString();
logthis("Batchfile" + BatchFile, 1);
File.Delete(BatchFile);
}
System.Threading.Thread.Sleep(5000);
RunBatch();

}

}

Now I'm not sure if any of the rest of the code is a problem but the
presence of RunBatch(); in RunBatch() is causing it to stall at load.
I've set the Sleep to be really high to avoid any problem like that
but it seems like that does not work. How does one get around that?

Apr 11 '08 #1
3 1894
The service-start method needs to exit promptly; in most cases, the
"start" to a service simply fires up a new thread to run (in this
case) RunBatch - i.e.

protected override void OnStart(string[] args)
{
Thread thread = new Thread(new ThreadStart(RunBatch));
thread.Name = "RunBatch";
thread.Start();
}

Also - why does this need to be recursive? It is surenly guaranteed to
blow the stack eventually... why not just "do/while" or similar?

Marc
Apr 11 '08 #2
On Apr 11, 9:15*am, pantagruel <rasmussen.br...@gmail.comwrote:
Hi,

I have the following:

*public static void RunBatch() {

* * * * * * if (OnDemandRunning) {
* * * * * * * *//If OnDemand is Running we will do nothing
* * * * * * }
* * * * * * else{

* * * * * * * * BatchDirectoryName = "C:\\BatchQ";
* * * * * * * * String[] BatchDirectory =
Directory.GetFiles(BatchDirectoryName,"*.xml");

* * * * * * for (int counter = 0; counter < BatchDirectory.Length;
counter++) {
* * * * * * * * * * ///<remarks>
* * * * * * * * * * /// need to break if an OnDemand event happens.
* * * * * * * * * * ///</remarks>
* * * * * * * * * * ///
* * * * * * //TODO: Implement actual event handling etc. instead of
the fake event handling doing now.
* * * * * * * * * * if (OnDemandRunning) { break; }
* * * * * * * * *String BatchFile =
BatchDirectory.GetValue(counter).ToString();
* * * * * * * * * *logthis("Batchfile" + BatchFile, 1);
* * * * * * * * * *File.Delete(BatchFile);
* * * * * * * * }
* * * * * * * * System.Threading.Thread.Sleep(5000);
* * * * * * * *RunBatch();

* * * * * * }

* * * * }

Now I'm not sure if any of the rest of the code is a problem but the
presence of RunBatch(); in RunBatch() is causing it to stall at load.
I've set the Sleep to be really high to avoid any problem like that
but it seems like that does not work. How does one get around that?
the OnStart method is intended to return at once.
Create a thread and do your processing there.

Question, what you do when the batch is completed? how the process
gets the next batch?
Apr 11 '08 #3
As Marc indicated, you want to do this kind of operation on a background
thread so your OnStart method returns quickly. Also, instead of Sleep you
probably want to use a timer.
-Peter
"pantagruel" <ra*************@gmail.comwrote in message
news:26**********************************@y18g2000 pre.googlegroups.com...
Hi,

I have the following:

public static void RunBatch() {

if (OnDemandRunning) {
//If OnDemand is Running we will do nothing
}
else{

BatchDirectoryName = "C:\\BatchQ";
String[] BatchDirectory =
Directory.GetFiles(BatchDirectoryName,"*.xml");

for (int counter = 0; counter < BatchDirectory.Length;
counter++) {
///<remarks>
/// need to break if an OnDemand event happens.
///</remarks>
///
//TODO: Implement actual event handling etc. instead of
the fake event handling doing now.
if (OnDemandRunning) { break; }
String BatchFile =
BatchDirectory.GetValue(counter).ToString();
logthis("Batchfile" + BatchFile, 1);
File.Delete(BatchFile);
}
System.Threading.Thread.Sleep(5000);
RunBatch();

}

}

Now I'm not sure if any of the rest of the code is a problem but the
presence of RunBatch(); in RunBatch() is causing it to stall at load.
I've set the Sleep to be really high to avoid any problem like that
but it seems like that does not work. How does one get around that?
Apr 11 '08 #4

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

Similar topics

0
by: TJ | last post by:
I am running PHP version 4.3.4 I am running an Apache server I am running on Windows 2000 My PHP server has run perfectly since it was installed last November. However, I just uncommented the...
0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
10
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. ...
2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
8
by: Ryan Stewart | last post by:
Putting the following code in a page seems to make it go into an infinite loop unless you give it a very simple node to work with. Either that or it's very very slow. I'm somewhat new to this,...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
4
by: Jerry Camel | last post by:
I'm posting this here because it seems to be a much more active group that the standard VB group and I suspect that ASP developers may be more inclined to write a service, anyway. I've got my...
5
by: Adrian | last post by:
Hi is this possible in VB.Net ? How should I go about it? The Idea is the service will run at a given time and shutdown the PC no matter what state it has been left in! Any pointers would...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.