Windows关闭时无法序列化类 [英] Cannot serialize class when windows shutdowns

查看:54
本文介绍了Windows关闭时无法序列化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在后台运行,通常最小化到托盘。应用程序尝试在Form_Closing事件中保存数据。如果用户直接关闭它,一切正常。用户关闭窗口时出现问题(我的应用程序在后台工作)。系统显示以下消息 - csc.exe应用程序错误:应用程序无法正确初始化(0xc0000142)。我在XmlSerializer构造函数上也得到了FileNotFoundException。

My application works in background, usually it minimized to tray. Application trys to save data in Form_Closing event. If user close it directly all works fine. Problem occurs when user shutting down windows (my app working in background). System shows following message - csc.exe Application Error : The application failed to initialize properly (0xc0000142). Also I got FileNotFoundException on XmlSerializer constructor.


推荐答案

让我了解一下这个场景 - 是你的应用程序托管在失败的机器上,还是客户端那是在关机的机器上?在这两种情况下,我都希望应用程序失败,当机器进入关机状态时,您无法继续处理。我建议在所有的"关闭"中使用一个Debug语句。类型事件(对不起,我不像以前那样按顺序记住它们)并查看哪些被调用。听起来您错过了一个事件来为您的应用调用Closing逻辑。我会假设在后台进程关闭后调用Form_Closing,因此出现错误。

年级
So let me understand the scenario - is it your application hosted on a machine that is failing, or the client that is on the machine that is being shut down?  In either case here, I would expect the app to fail, you cannot keep processing when the machine enters Shutdown state.  I would suggest puttin a Debug statement in all teh "closing" type events (I'm sorry, I don't remember them  in sequence as I once did) and see which ones get called.  It sounds like you are missing an event to call the Closing logic for your app. I would assume that Form_Closing is getting called after the background process is shutdown, hence the error.

Ed

这篇关于Windows关闭时无法序列化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆