while (true)
{
lock (groupslocker)
{
if (groups.Count == 0)
break;
else
gr = groups.Dequeue();
}
string url = rand_url();
int h = od_group_join(gr, url);
if (h == -1)
{
// How to return to this line string url = rand_url(); ???
}
else
.........
}
如何从if (h == -1)
返回到行string url = rand_url();
???
答案 0 :(得分:3)
听起来你想要一个循环:
int h;
string url;
do
{
url = rand_url();
h = od_group_join(gr, url);
} while (h == -1);
我已经重命名了你的方法和变量,但是很难从现在的名字中猜出一个合理的含义。我强烈建议您使用更有意义的名称,并遵循.NET命名约定。
答案 1 :(得分:1)
int h;
string url;
do
{
url = rand_url();
h = od_group_join(gr, url);
}
while(h == -1);
答案 2 :(得分:0)
while (true)
{
lock (groupslocker)
{
if (groups.Count == 0)
break;
else
gr = groups.Dequeue();
}
string url = rand_url();
int h = od_group_join(gr, url);
while (h == -1)
{
url = rand_url();
h = od_group_join(gr, url);
}
.........
}
答案 3 :(得分:0)
您可以使用递归方法调用。将该部分代码移动到一个操作中(我将其命名为SubOperation
)
static void SubOperation()
{
string url = rand_url();
int h = od_group_join(gr, url);
if (h == -1)
{
// How to return to this line string url = rand_url(); ???
SubOperation();
}
else
.........
}
然后修改原始代码以改为调用新操作?
while (true)
{
lock (groupslocker)
{
if (groups.Count == 0)
break;
else
gr = groups.Dequeue();
}
SubOperation();
}