带有BackgroundWorker的Excel Addin [英] Excel Addin with BackgroundWorker

查看:61
本文介绍了带有BackgroundWorker的Excel Addin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在VSTO 2010 Excel for Excel Addin中有一个Ribbon Designer。

在功能区设计器中,一个按钮-LoginBtn。

登录后按钮LoginForm将打开。

在loginForm一键 - ClickBotton。

如果我点击按钮,这个LoginForm将在20秒后隐藏。

在20秒的时间内,我想使用excel的单元格来使用。



我很困惑在哪里使用bachgroundworker。它是用丝带设计师或在LoginForm。

我的目标是在20秒内在excel文件中工作。



感谢你。

Hi,
I have a Ribbon Designer in VSTO 2010 Excel for Excel Addin.
In the ribbon Designer ,one button-LoginBtn.
After login button LoginForm will open.
In the loginForm One button-ClickBotton.
If i will click the button this LoginForm will hide after 20 sec.
Within that 20 sec time, i want to use the cell of excel for use.

I am confiuse where to use bachgroundworker .is it in ribbon Designer or in LoginForm .
My aim is to work in the excel file within that 20 sec.

Thanking you.

推荐答案

请参阅以下代码

使用backgroundWorker在关闭按钮上完成的工作



See the following code
Which is done at your close button using backgroundWorker

BackgroundWorker bw = new BackgroundWorker();
        private void button1_Click(object sender, EventArgs e)
        {
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
            if (bw.IsBusy != true)
            {
                bw.RunWorkerAsync();
            }
        }
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            //
            // Boring.... Do your long work
            //
            System.Threading.Thread.Sleep(20000);
        }
        private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (this.InvokeRequired)
            {
//Hide your form here
                this.Invoke(new MethodInvoker(delegate { this.Close(); }));
            }
        }


这篇关于带有BackgroundWorker的Excel Addin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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