使用BackgroundWorker类时UI挂起 [英] UI hangs while using BackgroundWorker class

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

问题描述



我需要在单击网页的按钮上运行后台进程,并且该页面不应该挂起/等待完成该进程,以便用户可以在Web应用程序上做任何想做的事情.

我的解决方案:

1)我使用BackgroundWorker类,即使我关闭了UI作业也完成了,但是如果我不关闭UI,它会挂起,直到处理完成.

2)我在WS中使用了webservice和backgroundworker clas.但是它显示出与第一个结果相同的结果.. :(


请帮助我..在后台工作时我需要UI是免费的..

提前谢谢.



干杯,
Divya

[edit]从主题中删除了紧急" [edit]

Hi,

I need to run a background process on a button click on a web page and the page shoud not hang/wait to complete the process so that user can do whatever he wants to do on the webapp.

My solutions:

1) I used BackgroundWorker class and even if I close the UI job gets done but if I dont close UI, It gets hang untill process gets complete.

2) I used webservice and used backgroundworker clas in WS. But it shows same result as the 1st one .. :(


Please help me .. I need UI to be free .. while workingon background job..

Thanks in advance.



Cheers,
Divya

[edit]Removed "urgent" from subject[edit]

推荐答案

您需要了解ASP.NET处理.在回发期间,无论生成了多少线程,页面都不会渲染,直到全部完成.

如果您要异步处理,则可以使用简单的UpdatePanel或其他更直接的方法(例如JQuery)来研究AJAX.
You need to understand ASP.NET processing. During a postback it doesn''t matter how many threads you spawn the page will not be rendered until all of completed.

If you want asynchronous processing then look into AJAX, either by using a simple UpdatePanel, or more direct means, such as JQuery.


Private Sub DoSomethingInBackGround()
        'System.Threading.Thread.Sleep(10000)
End Sub

Protected Sub btnRunInBackGround_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRunInBackGround.Click
        Dim backGroundThreadStart As New Threading.ThreadStart(AddressOf DoSomethingInBackGround)
        Dim backGroundThread As New Threading.Thread(backGroundThreadStart)
        backGroundThread.Start()
End Sub


这篇关于使用BackgroundWorker类时UI挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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