加载图像停止发行 [英] Loading image stops issue

查看:124
本文介绍了加载图像停止发行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows窗体。我已经把一个装载图像图片框

I have windows form. I have put one loading image in PictureBox

当我打开窗体,然后我已设置

When I load form then I have set

PictureBox1.Visible = false;



虽然我发射按钮的单击事件我已设置

While i am firing click event of button I have set

PictureBox1.Visible = true;



但在这种情况下有一些代码通过存储过程来检索数据库中的数据。

But in that event there is some code to retrieve data from database through stored procedure.

在它会跳转到的代码,用于从该加载图像停下来装载存储过程的数据。

When it will jump to code for retrieving data from stored procedure that loading image stops to load.

这不应该发生的事情。它应显示为加载。我已经使用.gif注意加载图像。

It should not be happened. It should show as loading. I have used .gif loading image.

我怎样才能解决这个问题呢?

How can I solve this issue ?

推荐答案

你有一个事件处理程序中的一个长期持久的通话每次你应该使用的BackgroundWorker !一个BackgroundWorker的可运行的代码异步的并为此您button_click事件处理程序将启动工作者之后结束。

Everytime you have a long lasting call within an eventHandler you should use a BackgroundWorker! A BackgroundWorker can run code async and therefor your button_click eventHandler will end right after starting the worker.

// add a BackGroundWorker bwLoadData to your form

private void YOURBUTTON_Click(object sender, EventArgs e)
{
     PictureBox1.Visible = true;
     bwLoadData.RunWorkerAsync();
}
private void bwLoadData_DoWork(object sender, DoWorkEventArgs e)
{
     // access your db, execute storedProcedue and store result to
     e.Result = YOUR_DATASET_RECORDS_OR_ANYTHING_ELSE;
}
private void bwLoadData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
     if (e.Result != null)
     {
          // e.g. show data on form
     } else {
          // e.g. error message
     }
}

这篇关于加载图像停止发行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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