473,387 Members | 1,812 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,387 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 1896
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
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,...
0
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...

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.