在同时BackgroundWorker的显示等待光标运行 [英] Displaying wait cursor in while backgroundworker is running

查看:285
本文介绍了在同时BackgroundWorker的显示等待光标运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows应用程序的开始,我必须做出对Web服务的调用来检索一些默认的数据加载到我的应用程序。在表格的负荷,我运行一个BackgroundWorker来获取这些数据。我想,直到数据被检索显示等待光标。我会怎么做呢?



我已经打过电话BackgroundWorker的运行之前将等待光标。当我报告的100的进度,然后我把它设回默认光标。该等待光标来了,但是当我移动鼠标消失



环境:




  • 的Windows 7专业版64位

  • VS2010 C#.NET 4.0

  • Windows窗体



编辑:
我设置光标的方式周杰伦里格斯建议。它只是如果我不移动鼠标的工作原理



* *更新:我创建了一个按钮,点击
这确实以下:当我做的按钮点击移动我的鼠标,如果我移动鼠标或不等待光标不管出现

 <。 code>无效BtnClick()
{
光标= Cursors.WaitCursor;
Thread.sleep代码(8000);
光标= Cursors.Default;
}

如果我做到以下几点:我看到等待光标当我移动表单内消失鼠标。如果我搬到我的状态栏或菜单栏出现等待光标



 光标= Cursors.WaitCursor。 
如果(backgroundWorker.IsBusy!)
{
backGroundWorker.RunWorkerAsync();
}

无效backGroundWorkerDoWork(对象发件人,DoWorkEventArgs E)
{
Thread.sleep代码(8000);
}

无效backGroundWorkerCompleted(对象发件人,RunWorkerCompletedEventArgs E)
{
光标= Cursors.Default;
}

如果我做到以下几点:出现等待光标,当我移动仍出现鼠标,但有时会闪烁关闭并在文本字段中移动时。虽然光标变为等待光标,它不会阻止你点击任何东西。



 如果( !backgroundWorker.IsBusy)
{
backGroundWorker.RunWorkerAsync();
}

无效backGroundWorkerDoWork(对象发件人,DoWorkEventArgs E)
{
UseWaitCursor = TRUE;
Thread.sleep代码(8000);
}

无效backGroundWorkerCompleted(对象发件人,RunWorkerCompletedEventArgs E)
{
UseWaitCursor = FALSE;
}


解决方案

确实 UseWaitCursor 工作? (调用的RunWorkerAsync(如果设置为true),假当完成事件被调用)。什么是你现在使用设置光标?


During the start of my windows application, I have to make a call to a web service to retrieve some default data to load onto my application. During the load of the form, I run a backgroundworker to retrieve this data. I want to display the wait cursor until this data is retrieved. How would I do this?

I've tried setting the wait cursor before calling the backgroundworker to run. When I report a progress of 100 then I set it back to the default cursor. The wait cursor comes up but when I move the mouse it disappears.

Environment:

  • Windows 7 Pro 64-bit
  • VS2010 C# .NET 4.0
  • Windows Forms

EDIT: I am setting the cursor the way Jay Riggs suggested. It only works if I don't move the mouse.

**UPDATE: I have created a button click which does the following: When I do the button click and move my mouse, the wait cursor appears regardless if I move my mouse or not.

void BtnClick()
{
  Cursor = Cursors.WaitCursor;
  Thread.Sleep(8000);
  Cursor = Cursors.Default;
}

If I do the following: I see the wait cursor and when I move the mouse it disappears inside the form. If I move to my status bar or the menu bar the wait cursor appears.

Cursor = Cursors.WaitCursor;
if (!backgroundWorker.IsBusy)
{
  backGroundWorker.RunWorkerAsync();
}

void backGroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
  Thread.Sleep(8000);
}

void backGroundWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
  Cursor = Cursors.Default;
}

If I do the following: The wait cursor appears and when I move the mouse it still appears but will sometimes flicker off and on when moving in text fields. Although the cursor changes to the wait cursor, it doesn't prevent you from clicking on anything.

if (!backgroundWorker.IsBusy)
{
  backGroundWorker.RunWorkerAsync();
}

void backGroundWorkerDoWork(object sender, DoWorkEventArgs e)
{
  UseWaitCursor = true;
  Thread.Sleep(8000);
}

void backGroundWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
  UseWaitCursor = false;
}

解决方案

Does UseWaitCursor work? (Set to true when calling RunWorkerAsync(), and false when the completion event is called). What are you using to set the cursor now?

这篇关于在同时BackgroundWorker的显示等待光标运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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