主窗口在WPF中关闭时取消后台工作程序 [英] cancel the background worker when the mainwindow closing in WPF

查看:62
本文介绍了主窗口在WPF中关闭时取消后台工作程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序中,



在此应用程序中,我使用的是一个用户控件。



在用户控制按钮单击事件中,我们正在启动一个后台工作。



在后台工作程序中,我们将一些数据导出到.Csv文件。



当这个过程正在运行时,我们需要在用户关闭主窗口时取消后台工作人员。



我的问题是我们如何用户关闭窗口时可以停止。



请提供您的想法。

In My WPF application,

In this Application i am using One user control.

In the user control button click event we are starting one backgroundworker.

In the background worker we are exporting some data to the .Csv file.

While this process is running we need to cancel the background worker when the user close the mainwindow.

My question is how we can stop when user closes the window.

Please provide me your ideas.

推荐答案

使用窗口WPF中存在已关闭的事件并编写代码(您想要停止的过程。)。
use the Window closed event present in WPF and write the code (the process you wanted to stop.).


这篇关于主窗口在WPF中关闭时取消后台工作程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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