English 中文(简体)
服务主计长 未给予我目前地位的情况
原标题:ServiceControllerStatus not giving me current status
  • 时间:2010-09-24 07:04:26
  •  标签:
  • c#

• 为我的一项服务取得服务控制员:

foreach (ServiceController sc in ServiceController.GetServices())
{
    if (sc.ServiceName == ConfigurationManager.SYNC_SERVICE_NAME)
    {
        this._serviceController = sc;
        break;
    }
}

并且当用户启动一项行动时,将地位功能称作:

private void tsmiStartServer_Click(object sender, EventArgs e)
{
    if (_serviceController.Status == ServiceControllerStatus.Stopped)                    
        this._serviceController.Start();
}

然而,即使服务中断,情况也会随着运行而出现。 事实上,在我获得服务控制员反对时,我似乎并不改变这一地位,以为它被发现和ched。

然而,我发现,如果我向地位财产发出呼吁之前再发出呼吁,就会发现服务的正确状况。 这似乎与“除我不再提及正确情况......”这一说法有何矛盾?

最佳回答

http://msdn.microsoft.com/en-us/library/system.serviceprocess.service Controller.refresh.aspx” rel=“nofollow”Refresh>,,以确保你具备以下条件:

private void tsmiStartServer_Click(object sender, EventArgs e)
{
    _serviceController.Refresh();
    if (_serviceController.Status == ServiceControllerStatus.Stopped)                    
        this._serviceController.Start();
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...