简体   繁体   English

VSTO Addin中长时间运行的任务中如何在UI上具有取消按钮?

[英]How to have cancel button on UI in long running task in VSTO Addin?

I created an Excel Addin in c# that goes through a couple 1000 rows and performs some updates on the cells. 我在c#中创建了一个Excel插件,它经过几千行并在单元格上执行了一些更新。 It is very long running and I would like the user the option to CANCEL if need be. 它运行时间很长,如果需要,我希望用户选择“取消”。

As it is by default the UI is not responsive during the processing. 由于默认情况下,UI在处理期间没有响应。

Is there something in the Excel Addin framework for this ? Excel插件框架中是否有此功能? Do I create a new thread? 我是否创建一个新线程? Would that cause issues with the ability to update the UI thread though? 但这会导致更新UI线程的能力出现问题吗?

Looking for some general direction or links to something to get me started. 寻找一些一般方向或链接以使我入门。

EDIT: The example given is for creating a simple button click event. 编辑:给出的示例是用于创建一个简单的按钮单击事件。 I understand that. 我明白那个。 I need to CANCEL a process within VSTO which is more complex. 我需要在VSTO中取消一个更复杂的过程。

The answer lies not with the Excel Object Model or the VSTO framework, but rather in .NET. 答案不在于Excel对象模型或VSTO框架,而在于.NET。 All you need is a BackgroundWorker class, which will automatically leverage multi-threading and easily facilitates cancelling the operation. 您只需要一个BackgroundWorker类,即可自动利用多线程并轻松地取消操作。 Here's a good article that can get you started: https://msdn.microsoft.com/en-us/library/hybbz6ke.aspx 这是一篇很好的文章,可以帮助您入门: https : //msdn.microsoft.com/zh-cn/library/hybbz6ke.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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