473,666 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recursive function causing service to stall at start up

Hi,

I have the following:

public static void RunBatch() {

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

BatchDirectoryN ame = "C:\\BatchQ ";
String[] BatchDirectory =
Directory.GetFi les(BatchDirect oryName,"*.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 (OnDemandRunnin g) { break; }
String BatchFile =
BatchDirectory. GetValue(counte r).ToString();
logthis("Batchf ile" + BatchFile, 1);
File.Delete(Bat chFile);
}
System.Threadin g.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 1906
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(Run Batch));
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.comwrot e:
Hi,

I have the following:

*public static void RunBatch() {

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

* * * * * * * * BatchDirectoryN ame = "C:\\BatchQ ";
* * * * * * * * String[] BatchDirectory =
Directory.GetFi les(BatchDirect oryName,"*.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 (OnDemandRunnin g) { break; }
* * * * * * * * *String BatchFile =
BatchDirectory. GetValue(counte r).ToString();
* * * * * * * * * *logthis("Batch file" + BatchFile, 1);
* * * * * * * * * *File.Delete(Ba tchFile);
* * * * * * * * }
* * * * * * * * System.Threadin g.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.comwrot e in message
news:26******** *************** ***********@y18 g2000pre.google groups.com...
Hi,

I have the following:

public static void RunBatch() {

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

BatchDirectoryN ame = "C:\\BatchQ ";
String[] BatchDirectory =
Directory.GetFi les(BatchDirect oryName,"*.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 (OnDemandRunnin g) { break; }
String BatchFile =
BatchDirectory. GetValue(counte r).ToString();
logthis("Batchf ile" + BatchFile, 1);
File.Delete(Bat chFile);
}
System.Threadin g.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
1565
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 line (I need PHP to interface with an Oracle database): extension=php_oracle.dll
0
6906
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
5664
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. Not being a computer scientist, I find recursive functions to be frightening and unnatural. I'd appreciate if anyone can tell me the pythonic idiom to accomplish this. Thanks for your help,
2
2881
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 a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display descending sequence of digits. I have not followed the instructions completely regarding the...
8
2214
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, having limited experience with hacking out JavaScript but no serious coding with it. I do have programming experience though. The logic seems fine to me. Is there something I'm missing? <script type="text/javascript"> var out = "";
4
9047
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. However, it is not as straightforward to determine the base address for my stack space. The approach I have taken is to save the address of an automatic variable in main( ), and assume this is a fairly good indicator of my base address. Then, I can...
4
1122
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 service all nice and compiled and it runs just great. Question is, how do I populate the description field in the Control Panel Services applet? Is it a registry hack or should I be able to set this within the service project in VS? Thanks. ...
5
1337
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 be helpful not written much and have never written a service :(
9
16815
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 type='text/javascript'> function myFunc(lev) { // if (lev) return myFunc(lev-1); var aStack=; nextFunc = arguments.callee;
0
8363
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8561
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8645
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5672
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.