I am a web developer who has not worked with windows development for many years. I suddenly have to change a windows service.
The windows service reads EDI files. I want to check for the existence of a row in a SQL table at the beginning of the code. If the row does not exist, then I want to stop processing the current EDI file and move on to the next file. I already have the code to check for the existence of the row. My question is: Is there an easy way to end processing of this file and move on the next file?
Wim SturkenboomPosted Dec 4, 2014, 11:45 PM
Assuming that your code is basically single threaded (only processing one file at a time), you can keep a bool in the Program class to indicate if you want to continue.
static class Program
{
public static bool WantToBailout=false;
static void Main()
{
You can set and check this everywhere in the existing code
private void someMethod()
{
if(Program.WantToBailout)
return;
// normal processing
...
...
if(!rowcheck())
{
Program.WantToBailout=true;
return;
}
}
private void anotherMethod()
{
if(Program.WantToBailout)
return;
someMethod();
if(Program.WantToBailout)
return;
...
...
}
But this is really bad programming making poorly written code even worse.
Bob HerrmannPosted Dec 1, 2014, 12:49 PM
Wim SturkenboomPosted Dec 1, 2014, 10:11 AM
// list of files to process
string[] files = .....;
// process all files
for(int cnt=0;cnt
// your sql processing
if(!checkrowexists())
continue;
// your file processing
processEditFile();
}
This could be the basic framework; notice the use of continue.