执行以下操作时,while
循环永远不会结束。我在这里调用一个方法来获取 while 循环条件的值。请告诉我我做错了什么?
using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.IO;
namespace BuildActivities
{
public sealed class CheckFile : CodeActivity
{
public InArgument<string> DirectoryName;
protected override void Execute(CodeActivityContext context)
{
Activity workflow = new Sequence
{
Activities =
{
new While
{
Condition = GetValue() ,
Body = new Sequence
{
Activities = {
new WriteLine
{
Text = "Entered"
},
new WriteLine
{
Text = "Iterating"
},
new Delay
{
Duration = System.TimeSpan.Parse("00:00:01")
}
}
}
//Duration = System.TimeSpan.Parse("00:00:01")
},
new WriteLine()
{
Text = "Exited"
}
}
};
try
{
WorkflowInvoker.Invoke(workflow, TimeSpan.FromSeconds(30));
}
catch (TimeoutException ex)
{
Console.WriteLine("The File still exist. Build Service has not picked up the file.");
}
}
public bool GetValue()
{
bool matched = false;
matched = File.Exists(@"\\vw189\release\buildservice\conshare.txt");
return matched;
}
}
}
当代码执行时,我认为它只是检查一次while条件。因为,我写了一些写行来检查它是如何工作的。我看到循环永远不会结束。我通过在循环运行时删除文件夹中的文件来测试这一点。有一项服务应该每 5 秒选择一次文件。这是为了确定该服务是否已启动并正在运行。