小编cri*_*jax的帖子

Windows服务OnStop等待完成处理

我实际上在VS 2012/.NET 4.5中开发了一个Windows服务.

该服务遵循以下代码段的方案:

  • 使用计时器
  • 每隔几分钟执行一些所需的操作.
  • 该过程大约需要10分钟才能完成
  • 我在服务中使用单个线程

我担心的是,如果有人通过管理控制台停止服务,它可能只是在服务正在进行的过程中.

我已经做了一些关于停止请求停止的Windows服务的阅读,但有点迷失.有时创建WorkerThreads,有时会创建ManualResetEvents,但到目前为止,我无法完全掌握Windows服务的最佳前进方法.

我需要等到处理在onStop方法中正确完成后再停止Windows服务.

那么最好的方法是什么,还要考虑下面的代码片段?

谢谢大家!

namespace ImportationCV
{
    public partial class ImportationCV : ServiceBase
    {
        private System.Timers.Timer _oTimer;       

        public ImportationCV()
        {
            InitializeComponent();

            if (!EventLog.SourceExists(DAL.Utilities.Constants.LOG_JOURNAL))
            {
                EventLog.CreateEventSource(DAL.Utilities.Constants.LOG_JOURNAL,     DAL.Utilities.Constants.SOURCE_JOURNAL);
            }

            EventLog.Source = DAL.Utilities.Constants.SOURCE_JOURNAL;
            EventLog.Log = DAL.Utilities.Constants.LOG_JOURNAL;
        }

        protected override void OnStart(string[] args)
        {            
            int intDelai = Properties.Settings.Default.WatchDelay * 1000;

            _oTimer = new System.Timers.Timer(intDelai);
            _oTimer.Elapsed += new ElapsedEventHandler(this.Execute);

            _oTimer.Start();           

            EventLog.WriteEntry(DAL.Utilities.Constants.LOG_JOURNAL, "Service " + DAL.Utilities.Constants.SERVICE_TITLE + " started at " + DateTime.Now.ToString("HH:mm:ss"), EventLogEntryType.Information);
        }

        protected override …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf windows-services single-threaded

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

从代码隐藏在Exchange服务器上创建公用文件夹

我必须在VB.Net Framework 4中创建一个项目管理应用程序,它应该在Exchange服务器的公用文件夹中创建一个客户端文件夹.

我认为创建公用文件夹的唯一方法是通过管理控制台.有没有办法连接到Exchange服务器并从代码执行创建命令文件,但我不知道如何.

还有另外一种方法吗?

c# vb.net exchange-server exchangewebservices public-folders

5
推荐指数
1
解决办法
2934
查看次数