代码之家  ›  专栏  ›  技术社区  ›  Harish Kumar

我的exe连接器突然停止在windows计算机上运行。(在visual studio中使用c#构建)

  •  -1
  • Harish Kumar  · 技术社区  · 5 年前

    我使用c#在visual studio中创建了一个服务应用程序,在windows机器上运行良好,但突然有一天它停止了工作。当我查看事件查看器时,我从那里得到了这个日志

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name=".NET Runtime" /> 
    <EventID Qualifiers="0">1026</EventID> 
    <Level>2</Level> 
    <Task>0</Task> 
    <Keywords>0x80000000000000</Keywords> 
    <TimeCreated SystemTime="2020-02-13T15:09:51.945244700Z" /> 
    <EventRecordID>32886</EventRecordID> 
    <Channel>Application</Channel> 
    <Computer>asus</Computer> 
    <Security /> 
    </System>
    <EventData>
    <Data>Application: sage50-uk-2019-v25.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidCastException at sage50_uk_2019_v25.Service1..cctor() Exception Info: System.TypeInitializationException at sage50_uk_2019_v25.Service1..ctor() at sage50_uk_2019_v25.Program.Main(System.String[])</Data> 
    

    我在网上通过了很多决议,但对我的情况没有任何帮助。 注:在其他机器上,它仍然工作。所以我想机器或windows操作系统上发生了一些事情。

    program.cs上我的主函数的代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace sage50_UK_v26_2_136_0
    {
        static class Program
        {
            static void Main()
            {
                Service1 myService = new Service1();
                myService.OnDebug();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
        }
    }
    

    服务等级的建造商:

    public partial class Service1 : ServiceBase
    {
        public void OnDebug()
        {
            OnStart(null);
        }
        protected override void OnStart(string[] args)
        {
            EventHandler handler = initApp;
            handler?.Invoke(this, null);
        }
    
        public void initApp(object sender, EventArgs e)
        {
            do
            {
                try
                {
                    // adding application into startup program
                    Microsoft.Win32.RegistryKey rkApp = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                    rkApp.SetValue(applicationName, "\"" + Application.ExecutablePath.ToString() + "\"");
                    deQueue(sender, e);
                    addTimer();
    
                }
                catch (Exception ex)
                {
                    WriteToLogFile("SDO Generated the Following Error: \n\n" + ex.Message);
                    System.Threading.Thread.Sleep(pauseThreadInMilliSeconds);
                    initApp(sender, e);
                }
    
                // loop while we're pending and the user is retrying
            } while (companyName == "" || apiKey == "");
        }
    }
    
    0 回复  |  直到 5 年前
    推荐文章