Dieter72: C# - Schleife funktioniert nicht ?

Beitrag lesen

Hallo,

ich bin gerade dabei mich ein wenig in C# auszutoben und stehe derzeit vor einem, für mich komischen, Problem.
Mit meinem nachfolgenden Code will ich den Thread 0-19 falls:
a) die INT restTLD > 0
und
b) einer der 20 Threats nicht läuft selbigen starten.
Die INT genauso wie die Counter-Variable sind mit korrekten Werten versehen (in dem Threat gibt es entsprechende Ausgaben).
Mein Problem an der ganzen Geschichte ist, das die Schleife genau nur einmal durchlaufen wird, obwohl dann z.B. in der INT restTLD noch ein Wert von z.b: 19 ist und alle Threats auf STOPPED stehen.

Das einzige wie ich mir das ganze Erklären kann, das es zu einer Exception kommt und dann dadurch die Schleife verlassen wird.

Im Debugger wirft das Teil übrigens nach dem ersten Durchlauf (ohne Fehler) eine Threat.Start-Exception - was aber n.m.E. doch eigentlich nicht dafür sorgen kann, das die WHILE abgebrochen wird, oder?

In den Threats wird übrigens eine Methode aufgerufen, die ebenfalls try/catch beinhaltet; dieses ist nicht umgänglich, da in dieser Methode Webrequests ausgeführt werden und es hierbei (leider) immer zu einer Exception kommen kann.

Daher hoffe ich, wie immer ;-), auf eure Hilfe...

  
                while (Program.restTLD > 0)  
                {  
                        if (Program.restTLD > 0 && t0.ThreadState != ThreadState.Running) { ++Program.counter; try{t0.Start(ezWURLS[Program.counter - 1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t1.ThreadState != ThreadState.Running) { ++Program.counter; try{t1.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t2.ThreadState != ThreadState.Running) { ++Program.counter; try{t2.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t3.ThreadState != ThreadState.Running) { ++Program.counter; try{t3.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t4.ThreadState != ThreadState.Running) { ++Program.counter; try{t4.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t5.ThreadState != ThreadState.Running) { ++Program.counter; try{t5.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t6.ThreadState != ThreadState.Running) { ++Program.counter; try{t6.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t7.ThreadState != ThreadState.Running) { ++Program.counter; try{t7.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t8.ThreadState != ThreadState.Running) { ++Program.counter; try{t8.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t9.ThreadState != ThreadState.Running) { ++Program.counter; try{t9.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t10.ThreadState != ThreadState.Running) { ++Program.counter; try{t10.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t11.ThreadState != ThreadState.Running) { ++Program.counter; try{t11.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t12.ThreadState != ThreadState.Running) { ++Program.counter; try{t12.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t13.ThreadState != ThreadState.Running) { ++Program.counter; try{t13.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t14.ThreadState != ThreadState.Running) { ++Program.counter; try{t14.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t15.ThreadState != ThreadState.Running) { ++Program.counter; try{t15.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t16.ThreadState != ThreadState.Running) { ++Program.counter; try{t16.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t17.ThreadState != ThreadState.Running) { ++Program.counter; try{t17.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t18.ThreadState != ThreadState.Running) { ++Program.counter; try{t18.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                        if (Program.restTLD > 0 && t19.ThreadState != ThreadState.Running) { ++Program.counter; try{t19.Start(ezWURLS[Program.counter-1]);} catch(Exception){} }  
                }

VG
Dieter