繁体   English   中英

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

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

我在 dot net core 3.1 中创建了一个控制台应用程序,它在运行时更改了现有 json 文件的值。 我使用以下命令创建了 exe 文件:

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

这是我的应用程序的代码:

 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;
    }
}

这个 exe 可以正常运行几天,但之后它停止工作并且 json 文件中的数据没有改变..我也没有收到任何错误。 请让我知道这里出了什么问题。

if (DateTime.Now <= liscencePeriod) ... 如果这是假的,它不会做任何事情,也不会给出任何错误。 您必须添加带有警告消息的 else。

正如我通过代码所看到的,您的应用程序运行一个然后停止执行。 为什么这样? 因为你没有任何循环(while/for/etc)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM