我有一个用C#编写的Windows服务,用于每隔几分钟执行一次任务.我正在使用它System.Timers.Timer
,但它似乎永远不会发射.我在SO和其他地方查看过很多不同的帖子,我没看到我的代码有什么问题.
这是我的代码,为清楚起见删除了与非计时器相关的项目...
namespace NovaNotificationService
{
public partial class NovaNotificationService : ServiceBase
{
private System.Timers.Timer IntervalTimer;
public NovaNotificationService()
{
InitializeComponent();
IntervalTimer = new System.Timers.Timer(60000); // Default in case app.config is silent.
IntervalTimer.Enabled = false;
IntervalTimer.Elapsed += new ElapsedEventHandler(this.IntervalTimer_Elapsed);
}
protected override void OnStart(string[] args)
{
// Set up the timer...
IntervalTimer.Enabled = false;
IntervalTimer.Interval = Properties.Settings.Default.PollingFreqInSec * 1000;
// Start the timer and wait for the next work to be released...
IntervalTimer.Start();
}
protected override void OnStop() …
Run Code Online (Sandbox Code Playgroud) 是在用户表中更好地表示用户权限还是在其自己的权限表中更好?
用户表
中的权限将权限放在用户表中意味着为用户表中的每个权限创建一列.优点是查询应该运行得更快,因为在将用户与用户权限相关联时不需要连接.缺点是拥有许多权限列会使用户表混乱.
权限表中的权限已连接到具有多对多关系的用户表
这样做可以干净地将权限从用户表中分离出来,但需要跨两个表进行连接才能访问用户权限.数据库访问速度可能较慢,但数据库设计似乎更清晰.
当有许多权限时,将权限保留在单独的表中可能会更好.做出这个决定还有哪些其他考虑因素,哪种设计在各种情况下更好?
在Visual Studio中,ReSharper警告:"可能多次枚举IEnumerable",代码如下:
static void Main(string[] args)
{
IEnumerable<string> items = Test2();
foreach (var item in items)
{
Console.WriteLine(item);
}
var newitems = new StringBuilder();
foreach (var item in items)
{
newitems.Append(item);
}
}
private static IEnumerable<string> Test2()
{
string[] array1 = { "1", "2", "3" };
return array1;
}
Run Code Online (Sandbox Code Playgroud)
我希望Test2方法将被调用两次,但它被调用一次.
我错过了什么?