简体   繁体   中英

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. I created the exe file by using following command :

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. 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. You have to add else with a warning message.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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