[已解决]已关闭表单,但进程仍在运行 [英] [Solved] Closed form but process is still running

查看:58
本文介绍了[已解决]已关闭表单,但进程仍在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序即使在用户关闭后仍能继续运行它的进程.我的项目设置是针对单个实例应用程序的,它是在名为Process.vb(应用程序中唯一的窗体)的窗体上启动的,并且关机"模式是启动窗体关闭时".

有很多代码,所以我想我只是解释一下它在做什么,并且希望有人能指出我一些我没有想到的...

该过程表单具有一些输入控件和一个按钮.按钮的on_click会将输入控制数据打包到一个类中,并调用backgroundworker异步将打包的数据传递给它,以避免交叉线程.后台工作程序的do_work调用访问数据库的方法.它还调用获取FileInfo和DirectoryInfo对象并使用System.IO来移动文件的方法,以及用于确定PDF文件中的页数的StreamReader的方法.后台工作者还报告进度.完成后,将创建一个字符串,其中包含有关已移动多少文件的信息,并将其设置为背景工作人员的结果.

如果我运行我的应用程序并且不按按钮,则一切都将正常关闭.因此,后台工作人员中一定有一些东西仍在打开或运行中,但我没有正确关闭,但是我不知道该怎么办.我回过头来,确保所有数据库控件都被释放并且连接被关闭.我的StreamReader对象被关闭并处置.我找不到在FileInfo对象上进行任何其他处置的方法.我也尝试在按钮中使用Application.Exit而不是关闭窗体,但仍然遇到相同的问题.

是否有人对无法妥善处理的常见问题有任何建议,或者提供一种调试和发现我错过的内容的方法?任何帮助,将不胜感激.谢谢.

I have an app that continues to have it''s process running even after the user has closed out of it. My project settings are for a single instance application, to startup on a form called Process.vb (the only form in the app), and the Shutdown mode is When startup form closes.

There is a lot of code, so I thought I''d just explain the basics of what it''s doing and hopefully someone can point me to something I haven''t thought of...

The process form has a few input controls and one button. The on_click of the button will package the input control data into a class and call a backgroundworker async passing the packaged data to it so as to avoid cross threading. The do_work of the background worker calls methods that access a database. It also calls methods that get FileInfo and DirectoryInfo objects and use System.IO to move files around and a StreamReader used to determine the number of pages in a PDF file. The background worker also reports progress. When finished a string with information about how many files were moved is created and set as the backgroundworker''s result.

If I run my app and don''t press the button everything closes properly. So there must be something in the backgroundworker that is still open or running that I haven''t closed properly, but I can''t figure out what. I''ve gone back and made sure all database controls get disposed and connections get closed. My StreamReader object gets closed and disposed. I couldn''t find a way to do any other disposing on the FileInfo objects. I also tried using Application.Exit in a button instead of the form closing and still have the same issue.

Does anyone have any suggestions for common things that do not get disposed properly, or a way to debug and find out what I missed? Any help would be appreciated. Thanks.

推荐答案

您要为后台工作人员呼叫CancelAsync吗?
Are you calling CancelAsync for the background worker?


最后找到了它.当访问数据库以更新一些数据时,这是一个问题,这些数据被多种方法深埋.在使用IBM.Data.DB2.iSeries.iDB2DataReader对象获取架构表后,我忘记了关闭它.

Finally found it. It was a problem when accessing the database to update some data that was buried several methods deep. I forgot to close an IBM.Data.DB2.iSeries.iDB2DataReader object after using it to get a schema table.

 Dim rdrSchema As IBM.Data.DB2.iSeries.iDB2DataReader
 Dim cmdSel As New IBM.Data.DB2.iSeries.iDB2Command

 'Retrieve File Schema
 cmdSel = inDaFile.SelectCommand
 rdrSchema = cmdSel.ExecuteReader(CommandBehavior.KeyInfo)
 dtSchema = rdrSchema.GetSchemaTable

'adding this statement fixed my issue
 rdrSchema.Close()



感谢那些建议可能出现问题的人!



Thanks to those who suggested possible problems!


这篇关于[已解决]已关闭表单,但进程仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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