小编Sha*_*lle的帖子

如何处理重复执行?

我试图验证我提出的解决方案,我认为这是一个相当典型的问题.我有一个服务运行,每10分钟应该做一些事情.我最终得到了以下内容:

private AutoResetEvent autoResetEvent = new AutoResetEvent(true);
private bool isRunning = true;

public void Execute()
{
    while(isRunning)
    {
       DoSomething();

       if(isRunning)
       {
         autoResetEvent.WaitOne(new Timespan(0, 10, 0));
       }
    }
}

public void Stop()
{
    isRunning = false;
    autoResetEvent.Set();
}
Run Code Online (Sandbox Code Playgroud)

我可以看到的直接潜在问题是,我没有对Stop()中的isRunning修改进行任何类型的锁定,这被另一个线程调用,但我不确定我真的需要吗?我认为最糟糕的情况是它会运行一个额外的周期.

除此之外,这段代码有任何明显的问题吗?有没有更好的方法来解决这个我不知道的问题?

c# multithreading recurring

3
推荐指数
1
解决办法
902
查看次数

使用 Maven 生成 XML 文件

我有一个如下所示的 XML 文件...

<foo>
   <bar>$VALUE$</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)

无论如何,我可以使用 Maven 合并这个 xml 文件和 .properties 文件吗?还是这个任务最好留给 Ant?

xml ant templates maven

3
推荐指数
1
解决办法
6367
查看次数

即使目录存在,nant directory :: exists也会返回false

我正在尝试检查目录是否作为NAnt脚本的一部分存在并获得误报.这是脚本片段:

<echo message="${backup.dir} --> ${directory::exists('${backup.dir}')}"/>
Run Code Online (Sandbox Code Playgroud)

这是输出:

[echo] D:\D\RTC\backup\20110223 --> False
Run Code Online (Sandbox Code Playgroud)

除了目录存在.

作为旁注,如果我跑..

<echo message="${backup.dir} --> ${directory::get-creation-time('${backup.dir}')}"/>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Expression: ${backup.dir} --> ${directory::get-creation-time('${backup.dir}')}
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Could not find a part of the path "D:\D\RTC\${backup.dir}".
Run Code Online (Sandbox Code Playgroud)

如果我跑..

<echo message="Directory Name --> ${path::get-directory-name('${backup.dir}')}"/>
Run Code Online (Sandbox Code Playgroud)

我明白了

[echo] Directory Name -->
Run Code Online (Sandbox Code Playgroud)

总而言之,我现在很困惑..有什么想法吗?

nant

3
推荐指数
1
解决办法
2305
查看次数

在隐藏字段中存储列表会导致奇怪的结果

public ActionResult DoSomething()
{
return View("Index", new IndexModel { Foo = new List<string>() { "*" });
}
Run Code Online (Sandbox Code Playgroud)

其中Index.cshtml有一个包含的表单 @Html.HiddenFor(m => m.Foo)

public ActionResult ProcessForm(IndexModel model)
{
}
Run Code Online (Sandbox Code Playgroud)

在ProcessForm中你的model.Foo包含一个字符串,其中包含:

System.Collections.Generic.List`1[System.String]
Run Code Online (Sandbox Code Playgroud)

我感到很困惑...

hidden-field razor asp.net-mvc-3

3
推荐指数
1
解决办法
3474
查看次数

对ASP注册表单页面的SQL注入攻击?

我需要知道ASP或ASP.Net对注册表单进行SQL注入攻击的过程吗?

sql asp.net sql-injection asp-classic

0
推荐指数
1
解决办法
2688
查看次数