简体   繁体   中英

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. 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.

Is there something in the Excel Addin framework for this ? Do I create a new thread? Would that cause issues with the ability to update the UI thread though?

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.

The answer lies not with the Excel Object Model or the VSTO framework, but rather in .NET. All you need is a BackgroundWorker class, which will automatically leverage multi-threading and easily facilitates cancelling the operation. Here's a good article that can get you started: https://msdn.microsoft.com/en-us/library/hybbz6ke.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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