关于一个winform的一个简单问题(一旦解决立即结账!)

softwareCRAZY 2008-12-22 10:07:42
我的程序只有一个窗体,里面有一些按钮,其中有一个按钮,单击这个按钮就是把一个excel文件里面的数据导入到oracle 中,但是通常点击后导数的程序会执行好久,因为数据很大 一般 有可能要一个钟头, 问题是: 我点击完按钮后,我的窗体将不响应任何事件,例如我想单击别的按钮或者操作别的控件是不可以的, 请问我怎样在执行导数的同时让我得程序能响应其他事件 谢谢! 一旦解决问题立即结账!
...全文
119 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
pele007 2008-12-22
  • 打赏
  • 举报
回复
BackgroundWorker来做吧,比自己建线程好一些,楼主MSDN一下即可
fuyuxin19801120 2008-12-22
  • 打赏
  • 举报
回复
Thread myThread = new Thread(new System.Threading.ThreadStart(导入excel方法的方法名称));
myThread.IsBackground = true;
myThread.Start();
gsmlove 2008-12-22
  • 打赏
  • 举报
回复
简单的解决方法
开始导入时,画面设置一个标志,不响应画面上的事件。
当导入结束后,更改标志。

比如在关闭按钮clicked中
if(flg==false)
{
return;
}

wuyq11 2008-12-22
  • 打赏
  • 举报
回复
通过多线程实现。
参考
http://www.cnblogs.com/warewing/archive/2008/05/29/1209966.html
http://www.cnblogs.com/guoyinghai/archive/2008/07/08/1167136.html
jinjazz 2008-12-22
  • 打赏
  • 举报
回复
 private void button1_Click(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(Start)).Start();
//旧的代码去掉
}

private void Start()
{
//旧的代码放到这里
}
HDNGO 2008-12-22
  • 打赏
  • 举报
回复

worker= new BackgroundWorker();
// Specify that the background worker provides progress notifications
worker.WorkerReportsProgress = true;
// Specify that the background worker supports cancellation
worker.WorkerSupportsCancellation = true;
// The DoWork event handler is the main work function of the background thread
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
// Specify the function to use to handle progress
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.ProgressChanged += new ProgressChangedEventHandler(progressForm.OnProgressChanged);
// Specify the function to run when the background worker finishes
// There are three conditions possible that should be handled in this function:
// 1. The work completed successfully
// 2. The work aborted with errors
// 3. The user cancelled the process
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerCompleted+=new RunWorkerCompletedEventHandler(progressForm.OnProcessCompleted);

//If your background operation requires a parameter,
//call System.ComponentModel.BackgroundWorker.RunWorkerAsync
//with your parameter. Inside the System.ComponentModel.BackgroundWorker.DoWork
//event handler, you can extract the parameter from the
//System.ComponentModel.DoWorkEventArgs.Argument property.
worker.RunWorkerAsync(leftList);
sprc_lcl 2008-12-22
  • 打赏
  • 举报
回复
using System.Threading;


private void ImportData()
{
//取excel的数据
//导入数据库
}
private void btnImport_Click(object sender, EventArgs e)
{
Thread thr1 = new Thread(ThreadStart(ImportData));
thr1.Start();
}

所有导数据的操作都写在ImportData函数内
jinjazz 2008-12-22
  • 打赏
  • 举报
回复
多线程就可以了,另外excel倒入oracle数据库可以参考
http://blog.csdn.net/jinjazz/archive/2008/07/21/2686526.aspx
softwareCRAZY 2008-12-22
  • 打赏
  • 举报
回复
不好意思, 能给我提供简单的程序么?谢谢 不要全部,关键性提示代码 即可 ,非常感谢
ljhcy99 2008-12-22
  • 打赏
  • 举报
回复
backgroundWorker有异步操作的功能,
用这个控件,在他的Do_work里面写代码。
xupeiying 2008-12-22
  • 打赏
  • 举报
回复
这个要用的多线程,让数据如导入在后台线程里进行。
sprc_lcl 2008-12-22
  • 打赏
  • 举报
回复
开个线程.
HDNGO 2008-12-22
  • 打赏
  • 举报
回复
BackgroundWorker或者另开一个线程~
gogogo 2008-12-22
  • 打赏
  • 举报
回复
导数的过程弄在另外一个线程里做。
mykelly6 2008-12-22
  • 打赏
  • 举报
回复
是不是要再开一个线程~

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧