【问题标题】:Windows services terminating near JsonConvert.DeserializeObjectWindows 服务在 JsonConvert.DeserializeObject 附近终止
【发布时间】:2019-10-08 21:47:22
【问题描述】:

下面是为复制文件的窗口服务编写的代码。 它从“JsonConvert.DeserializeObject>(jsonStirng);”行终止

public static void copyfiles()
{
    getLog("Before querying");
    SqlDataReader reader = select();
    if (reader.HasRows)
    {
        reader.Read();               
        string jsonStirng = reader["parameter"].ToString();
        getLog("Found rows" + jsonStirng); // this will get log with values
        try
        {

            var result = JsonConvert.DeserializeObject<List<RootObject>>(jsonStirng);
            getLog("result =>" + result[0].FOLDER_NAME); // this ignore, if remove above line, this log will work.
            // continue logic for copying files..
            }

        }
        catch (Exception e)
        {
            getLog("Fail to copy files"+e);
        }

    }
    else
    {
        getLog("No rows found.");
    }
    reader.Close();
}

下面是我得到的日志

ID  DATE    THREAD  LEVEL   LOGGER  MESSAGE
141 2019-05-22 17:09:02.273 Windows Services-Copy files INFO    OS  Found rows[{"FOLDER_TYPE":"UPLOAD_FOLDER","FOLDER_NAME":"UPLOAD_FOLDER\\"},{"FOLDER_TYPE":"DATA_FOLDER","FOLDER_NAME":"E:\\Suresh\\Projects\\TribandBISE\\BISE_C\\BISE_C\\DATA_FOLDER\\"},{"FOLDER_TYPE":"SOURCE_FOLDER","FOLDER_NAME":"SOURCE_FOLDER\\"},{"FOLDER_TYPE":"DB_BACKUP_FOLDER","FOLDER_NAME":"DATA_FOLDER\\DB_BACKUP_FOLDER"}]
140 2019-05-22 17:09:02.250 Windows Services-Copy files INFO    OS  inside select 
139 2019-05-22 17:09:02.240 Windows Services-Copy files INFO    OS  Before querying
138 2019-05-22 17:09:02.230 Windows Services-Copy files INFO    OS  Code initiated
137 2019-05-22 17:09:02.220 Windows Services-Copy files INFO    OS  windows service Copy_Data_Files initiated
136 2019-05-22 17:05:40.353 Windows Services-Copy files INFO    OS  error in init windows service
135 2019-05-22 17:05:40.050 Windows Services-Copy files INFO    OS  Code initiated

【问题讨论】:

  • 你得到什么异常?您能否将异常详细信息添加到您的问题(类型、消息等)中?
  • 它没有来捕获块,甚至“事件查看器”显示“服务启动成功。”
  • 你能告诉我们日志输出是什么样的吗?您似乎在不同点记录数据——哪些日志条目受到打击?
  • @bvoyelr 添加了日志
  • 根据您的日志,它显示“init windows service 中的错误”。记录该消息的代码在哪里?

标签: c# windows-services jsonconvert


【解决方案1】:

您可以通过更改服务的主入口点,像普通应用程序一样单步执行您的服务。

static void Main()
{
/////IF DEBUG The service will create all resource and allow code stepthrough
#if (!DEBUG)
    //NO DEBUG - Production code ran here
    System.ServiceProcess.ServiceBase[] ServicesToRun;
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyService() };
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#else
    // Debug code: this allows the process to run as a non-service.
    // It will kick off the service start point, but never kill it.
    // Shut down the debugger to exit
    MyService service = new MyService();
    service.OnStart(null);    
    System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#endif 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 2012-03-12
    相关资源
    最近更新 更多