下面的C#锐利代码不起作用 [英] Below C# sharp code isn't working

查看:84
本文介绍了下面的C#锐利代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private static void CloseOutlook()
{
    if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
     {
         var app = Marshal.GetActiveObject("Outlook.Application") as Outlook._Application;
         app.Quit();
     }
}
public class FileMove
{
    static void Main()
    {
        string sourceFile = @"C:\Users\IBM_ADMIN\AppData\Local\Microsoft\Outlook\rahul.dinesh@bp.com.ost";
        string destinationFile = @"C:\Users\IBM_ADMIN\AppData\Local\Microsoft\rahul.dinesh@bp.com.ost ";
        System.IO.File.Move(sourceFile, destinationFile);
    }
}   
Outlook error: "Outlook has stopped working"   1. Close Outlook and Skype 2. Move the ost file (C:\Users\uxxxxxxx\AppData\Local\Microsoft\Outlook) to upper folder) 3. Restart Outlook.   



private static void RestartOutlook()
{
    if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
     {
         var app = Marshal.GetActiveObject("Outlook.Application") as Outlook._Application;
         app.Quit();
     }
 
     Thread.Sleep(500);
     Process process = new Process();
     process.StartInfo = new ProcessStartInfo(OutlookFilepath);
     process.Start();
}





我的尝试:



请帮助解决C#代码问题



What I have tried:

Please help in trouble shooting the C# code

推荐答案

好吧,我将尝试用我的水晶球来解决这个问题,因为你很明显 - 措辞无问题。



关闭Outlook的方法应该更像这样:



Well, I'm going to try divining the solution with my crystal ball because of yourvaguely-worded non-question.

Your method to close Outlook should look more like this:

private static void CloseOutlook()
{
    // get all of the instances of outlook that are currently running
    Process[] outlooks = Process.GetProcessesByName("OUTLOOK");

    // kill each one, one at a time
    foreach (Process outlook in outlooks)
    {

        // kill the process
        int id = outlook.Id;
        outlook.Kill();

        // loop until the process is dead
        Process proc = null;
        do
        {
            proc = Process.GetProcessById(id);
            if (proc != null)
            {
                Thread.Sleep(250);
            }
        } while (proc <> null);
    }
}





要重启outlook,您需要在系统上找到可执行文件,然后执行它。查找相应的注册表项以查找安装位置,并使用 Process 类启动它。


这篇关于下面的C#锐利代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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