如何在win form应用中使用Windows服务 [英] how to use windows services in win form appliction

查看:81
本文介绍了如何在win form应用中使用Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有

i想知道如何创建用于备份sql server数据库的Windows服务以及如何将此服务用于我的win表单应用程序。







先谢谢

Dear all
i want to know how to create windows services for backup of sql server database and how to use this service to my win form application .



Thanks in Advance

推荐答案

使用以下代码,您将能够从获胜表单访问您的本地服务。

With the below code you will be able to access your local service from a win form.
// ADD "using System.ServiceProcess;" after you add the 
// Reference to the System.ServiceProcess in the solution Explorer
using System.ServiceProcess;

ServiceController myService = new ServiceController();    
myService.ServiceName = "ImapiService";

string svcStatus = myService.Status.ToString();

if (svcStatus == "Running")
{
    myService.Stop();
}
else if(svcStatus == "Stopped")
{
    myService.Start();
}
else
{
    myService.Stop();
}



本文可以帮助您使用C#代码备份sql数据库。



如何在c#窗口应用程序中创建备份和恢复数据库 [ ^ ]



编写代码来备份服务中的数据库。



快乐编码。



已添加代码块[/编辑]


This article may help you to take a backup of sql database with C# code.

How create Backup and Restore database in c# window application[^]

Write code to backup the database in service.

Happy Coding.

Code block added[/Edit]


服务是一项服务。它做了一些事情。

如果你在其中放置一个IPC接口,你可以从一个应用程序与它进行通信。我想你想添加SQL Server Express缺少的服务器代理功能。

为了做备份本身,我建议你使用 SMO备份类 [ ^ ]。

For您可以使用WCF,命名管道,MSMQ甚至普通TCP。但是如果你只想发送一条简单的信息,比如做备份,这个也可以是一个解决方案: http://arcanecode.com/2007/05/30/windows-services-in-c-sending-commands-to-your- windows-service-part-7 / [ ^ ]
A service is a service. It does something.
If you put an IPC interface in it you can communicate with it from an application. I suppose you want to add the missing Server Agent feature of SQL Server Express.
For doing the backup itself I suggest you use SMO Backup class[^].
For the IPC you can use WCF, named pipes, MSMQ, or even plain TCP. But if you want to send only a simple message, like "do backup", this one can be also a solution: http://arcanecode.com/2007/05/30/windows-services-in-c-sending-commands-to-your-windows-service-part-7/[^]


查看此链接



visual studio中的Windows服务 [ ^ ]


这篇关于如何在win form应用中使用Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆