简体   繁体   English

几天后 dot net core 控制台应用程序自动停止工作

[英]Dot net core console application stops working automatically after few days

I have created a console application in dot net core 3.1 which changes the values of existing json file on running.我在 dot net core 3.1 中创建了一个控制台应用程序,它在运行时更改了现有 json 文件的值。 I created the exe file by using following command :我使用以下命令创建了 exe 文件:

dotnet publish -r win-x86 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true dotnet publish -r win-x86 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true

here is the code for my application:这是我的应用程序的代码:

 static void Main (string[] args) {
        try {
            // blah blah.. some code to get liscence period
                if (DateTime.Now <= liscencePeriod) {
                    var processor = new JsonDataProcessor ();
                    processor.AmmendJsonData ();
                } 
            }
        } catch (Exception ex) {
            var errorFile = Path.Combine (Environment.CurrentDirectory, "JsonEditorError.txt");
            File.WriteAllText (errorFile, $"{ex.Message}");
        }
        
    }

 //AmmendJsonData code inside JsonDataProcessor class
internal void AmmendJsonData () {
    try {
        var jsonPath = Path.Combine (Environment.CurrentDirectory, "AVLJsonFile.json");
        var jsonData = File.ReadAllText (jsonPath);
        var jsonSchema = JsonConvert.DeserializeObject<Root> (jsonData);
        ChangeJsonContent (jsonSchema);
        var newJson = JsonConvert.SerializeObject (jsonSchema, Formatting.Indented);
        File.WriteAllText (jsonPath, newJson);
    } catch (Exception ex) {
        throw ex;
    }
}

This exe runs fine for few days but after that it stops working and data in json file doesn't change.. I also don't get any error.这个 exe 可以正常运行几天,但之后它停止工作并且 json 文件中的数据没有改变..我也没有收到任何错误。 Please let me know whats going wrong here.请让我知道这里出了什么问题。

if (DateTime.Now <= liscencePeriod) ... If this is false it will not do anything and dont give any error. if (DateTime.Now <= liscencePeriod) ... 如果这是假的,它不会做任何事情,也不会给出任何错误。 You have to add else with a warning message.您必须添加带有警告消息的 else。

As I can see by code, your application runs ones and then stop execution.正如我通过代码所看到的,您的应用程序运行一个然后停止执行。 Why so?为什么这样? Because you don't have any loop (while/for/etc)因为你没有任何循环(while/for/etc)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 dot net core 控制台应用程序中使用 BackgroundService - Can I use BackgroundService in dot net core console application 登录.Net核心控制台应用程序不起作用 - Logging in .Net core console application not working 获取在 .Net Framework Console 应用程序中工作的安全 .Net Core 代码 - getting security .Net Core code working in .Net Framework Console application 几分钟后,C#控制台应用程序的一部分停止工作。 请自己复制并粘贴此控制台应用代码 - Part of console app stops working after a few minutes C#. Please copy and paste this console app code for yourself 为点网(不是点网核心)应用程序创建 Dockerfile - Create a Dockerfile for a dot net (not dot net core) application 运行 .NET 核心控制台应用程序 - Running a .NET Core Console Application 发布 dot net core 2 应用程序后启动应用程序时发生错误 - an error occurred while starting the application after publishing dot net core 2 app WPF WebBrowser控件上的onmousemove侦听器在几秒钟后停止工作 - onmousemove listener on WPF WebBrowser control stops working after few seconds 使用IIS Express几秒钟后站点停止工作 - Site stops working after few seconds with IIS Express HttpWebRequest突然停止工作,几个请求后没有收到响应 - HttpWebRequest stops working suddenly, No response received after few requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM