相关疑难解决方法(0)

Windows Service System.Timers.Timer未触发

我有一个用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)

.net service windows-services timer

31
推荐指数
4
解决办法
3万
查看次数

.NET Windows服务中的消息泵

我有一个用C#编写的Windows服务,它处理自助服务终端应用程序的所有外部硬件I/O. 我们的新设备之一是USB设备,它在本机DLL中附带API.我创建了一个正确的P/Invoke包装类.但是,必须使用HWnd将此API初始化为Windows应用程序,因为它使用消息泵来引发异步事件.

除了向硬件制造商请求我们提供不依赖于Windows消息泵的API之外,有没有办法在我的Windows服务中的新线程中手动实例化消息泵,我可以将其传递给此API ?我是否真的必须创建一个完整的Application类,或者是否有一个封装消息泵的低级.NET类?

.net c# service message-pump

25
推荐指数
1
解决办法
2万
查看次数

System.Windows.Forms.Timer是否在与UI不同的线程上运行?

我有一个主线程创建一个表单对象,它创建并设置一个计时器,每分钟运行一个名为updateStatus()的函数.但是updateStatus()也被主线程在几个地方调用.

但是,我不清楚它是否会导致任何同步问题.C#中的System.Windows.Forms.Timer是否在主线程以外的其他线程上运行?

.net c# timer winforms c#-4.0

23
推荐指数
4
解决办法
2万
查看次数

在Windows服务中不调用计时器tick事件

我有一个窗口服务,它在指定的时间播放声音文件,所以为了做到这一点,我已经采取了Timer但它的Tick事件永远不会被触发,同样在WinForm应用程序中工作.

以下是我服务的代码片段......

public partial class ClockService : ServiceBase
{
    private TimeSpan _alarmTime = new TimeSpan(9, 55, 0);
    private int _snoozeTime = 2; // 2 minutes
    private int _repeatCounter = -1;
    private const int ALARM_REPETITION = 5;
    private string _alarmSoundPath = @"C:\Sound\default.wav";
    private string _alarmLogPath = @"C:\Sound\log.txt";

    public ClockService()
    {
        InitializeComponent();
        alarmTimer.Enabled = true;
    }

    protected override void OnStart(string[] args)
    {
        using (FileStream fileStream = new FileStream(_alarmLogPath, FileMode.OpenOrCreate))
        {
            using (StreamWriter writer = new StreamWriter(fileStream))
            {
                writer.WriteLine("Service has started at {0}", …
Run Code Online (Sandbox Code Playgroud)

c#

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

标签 统计

.net ×3

c# ×3

service ×2

timer ×2

c#-4.0 ×1

message-pump ×1

windows-services ×1

winforms ×1