使用C#中的文件系统过度使用服务 [英] Over ride a service using File System in C#

查看:52
本文介绍了使用C#中的文件系统过度使用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了两个应用程序:



1.安装程序(安装服务)



2.升级(停止并覆盖已经安装的服务)



当我运行升级时,我得到的例外是



进程无法访问文件E:\TF50 \SSS Service \ DataModel.dll,因为



它被另一个进程使用 。



这是我的示例代码:



I Developed two Applications :

1. Installer (Install Services )

2. Upgrade (Stop and Overwrite the Services that are already Installed)

When I run Upgrade, I m getting the Exception as

"The Process Cannot Access the File E:\TF50\SSS Service\DataModel.dll because

it is being used by another Process".

Here is my Sample Code :

try
   
{
     
if (xmlnode.Item(1).InnerText.ToString() != "")
       
{
         
 ServiceController sc = new ServiceController();
          
sc.ServiceName = "RT60Service";

           richTextBox1.Invoke((MethodInvoker)delegate
           {
           richTextBox1.Text = richTextBox1.Text + "RT60WindowService Started" +

 " - " + DateTime.UtcNow + Environment.NewLine;
                       
 });
                        
if (sc.Status == ServiceControllerStatus.Running)
                            
sc.Stop();

                        
fnUnZIP(xmlnode.Item(1).InnerText.ToString(), lstrHomeDirectory + 

"RT60WindowsService", "RT60WindowService");
                        
sc.Refresh();
                       
 if (sc.Status == ServiceControllerStatus.Stopped)
                        
{
                            
sc.Start();
                            
sc.Refresh();
                        
}
                        
richTextBox1.Invoke((MethodInvoker)delegate
                        
{
                            
richTextBox1.Text = richTextBox1.Text + "RT60WindowService Completed" + " - " + 

DateTime.UtcNow + Environment.NewLine;
                            
richTextBox1.Text = richTextBox1.Text + "---------------------------------------

---------------------------------------------------------" + 

Environment.NewLine;
                        
});
                    
}
                
}
                
catch (Exception ex)
                
{
                    
richTextBox1.Invoke((MethodInvoker)delegate
                    
{
                        
richTextBox1.Text = richTextBox1.Text + ex.Message + Environment.NewLine;

richTextBox1.Text = richTextBox1.Text + "RT60WindowService Failed" + " - " + 

DateTime.UtcNow + Environment.NewLine;

richTextBox1.Text = richTextBox1.Text + "---------------------------------------

---------------------------------------------------------" + 

Environment.NewLine;
                    
});
                
}
                
finally
                
{
                    
bgworker.ReportProgress(32);
                
}



现在我的问题是:'我们如何使用文件系统覆盖服务?'



我被困在这里,请帮助我解决..



先谢谢


Now My Question is : 'How can we Override a Service using a filesystem??'

I got stuck here and Please help me on dis ..

Thanks in Advance

推荐答案

您可能需要在调用停止之后留出更多时间,因为您尝试覆盖该文件。使用 sc.Status 信息检查它是否已完全停止。
You may need to leave more time after calling Stop befor you try to overwrite the file. Use the sc.Status information to check that it has completely stopped.


这篇关于使用C#中的文件系统过度使用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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