异步线程没有释放UI [英] Async thread not freeing up UI

查看:76
本文介绍了异步线程没有释放UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下线程设置,以便在进行

巨大过程时释放UI:


(声明代表)(AB和C全局)


Private Sub AB_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理AB.Click

Dim NoArg1 As New NoArgs(地址AxB)

NoArg1.BeginInvoke(没什么,没什么)

结束子


Private Sub AxB()

Dim mult作为新的TwoArgs(AddressOf solver.Matrix_Multiply)

Dim AsyncResult由于IAsyncResult = mult.BeginInvoke(A,B,Nothing,

没什么)

Do AsyncResult.IsCompleted

For i = 1 To 1000000:Next:Button3.Text = Rnd()。ToString

循环

C = mult.EndInvoke(AsyncResult)

用C做其他东西

End Sub


Matrix_Multiply是类求解器,使用

超线程P4消耗50%的CPU资源。它是浮点算术密集型。当我运行

程序时,UI无法使用,直到最终的C结果 - 获得双倍(,) -

。 Button3.text最初显示活动但随后停止。

线程逻辑适用于只运行循环的本地函数然后

返回一个字符串。


什么''错了?如何解决?

-

mark b

Please consider the following thread setup intended to free-up the UI while a
huge process takes place:

(declare delegates) (A B and C all global)

Private Sub AB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AB.Click
Dim NoArg1 As New NoArgs(AddressOf AxB)
NoArg1.BeginInvoke(Nothing, Nothing)
End Sub

Private Sub AxB()
Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A, B, Nothing,
Nothing)
Do Until AsyncResult.IsCompleted
For i = 1 To 1000000 : Next : Button3.Text = Rnd().ToString
Loop
C = mult.EndInvoke(AsyncResult)
do other stuff with C
End Sub

Matrix_Multiply is the class solver and consumes 50% of CPU resources with a
hyperthreading P4. It is floating point arithmatic intensive. When I run the
program the UI is unavailable until the final C result - which is double(,) -
is obtained. Button3.text initially shows activity but then stops. The
threading logic works fine with a local function that simply runs a loop then
returns a string.

What''s wrong? How fix?
--
mark b

推荐答案

Hello Mark ,,,


这个aproach只能在MP系统上运行,你可以通过使用线程和创建工作符来实现你想要的(响应gui)

>
线程作为较低的prio后台线程


Ofcourse会导致更长的处理时间(需要更长的时间才能完成你的应用程序) />

问候


Michel Posseth [MCP]


" mark" <毫安** @ discussions.microsoft.com>在消息中写道

新闻:BB ********************************** @ microsof t.com ...
Hello Mark ,,,

This aproach will only work on a MP system , you could possibly acomplish
what you want ( responsive gui ) by using threading and create the worker
threads as lower prio background threads

Ofcourse will this result in longer processing time ( takes longer before
you app is finished )

regards

Michel Posseth [MCP]

"mark" <ma**@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
请考虑以下线程设置,以便在进行大量过程时释放UI

(声明代理)(AB和C全局)

私有子AB_Click(ByVal发送者As System.Object,ByVal e As
System.EventArgs)处理AB.Click
Dim NoArg1作为新的NoArgs(地址为AxB)
NoArg1.BeginInvoke(Nothing,Nothing)
End Sub

私有子AxB()
Dim mult作为新的TwoArgs(AddressOf solver.Matrix_Multiply)
Dim AsyncResult因为IAsyncResult = mult.BeginInvoke(A,B,Nothing,
Nothing)
直到AsyncResult.IsCompleted
对于i = 1到1000000:Next :Button3.Text = Rnd()。ToString
循环
C = mult.EndInvoke(AsyncResult)
用C做其他东西
结束子

Matrix_Multiply是类solv通过
超线程P4消耗50%的CPU资源。它是浮点算术密集型。当我运行
程序时,UI无法使用,直到最终的C结果 - 即
double(,) -
获得。 Button3.text最初显示活动但随后停止。
线程逻辑可以正常工作,只需运行一个循环
然后
返回一个字符串。

有什么问题?如何修复?
-
标记b
Please consider the following thread setup intended to free-up the UI
while a
huge process takes place:

(declare delegates) (A B and C all global)

Private Sub AB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AB.Click
Dim NoArg1 As New NoArgs(AddressOf AxB)
NoArg1.BeginInvoke(Nothing, Nothing)
End Sub

Private Sub AxB()
Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A, B, Nothing,
Nothing)
Do Until AsyncResult.IsCompleted
For i = 1 To 1000000 : Next : Button3.Text = Rnd().ToString
Loop
C = mult.EndInvoke(AsyncResult)
do other stuff with C
End Sub

Matrix_Multiply is the class solver and consumes 50% of CPU resources with
a
hyperthreading P4. It is floating point arithmatic intensive. When I run
the
program the UI is unavailable until the final C result - which is
double(,) -
is obtained. Button3.text initially shows activity but then stops. The
threading logic works fine with a local function that simply runs a loop
then
returns a string.

What''s wrong? How fix?
--
mark b





首字母缩略词MP是多处理器?如果是这样,你认为双核处理器

可以做到这一点。我已经考虑过内存访问是问题的可能性

因为我的Matrix_multiply sub正在乘以数组。


-

mark b

" m.posseth"写道:

The acronym MP is multiprocessor? If so, do you think dual core processors
can do it. I have considered the posibility that memory access is the problem
as my Matrix_multiply sub is multiplying arrays.

--
mark b
"m.posseth" wrote:
Hello Mark ,,,

这个aproach只适用于MP系统,你可以实现你想要的(响应) gui)通过使用线程并创建工作线程作为较低的prio背景线程

当然会导致更长的处理时间(在应用程序完成之前需要更长时间)
Michel Posseth [MCP]

标记 <毫安** @ discussions.microsoft.com>在消息中写道
新闻:BB ********************************** @ microsof t.com。 ..
Hello Mark ,,,

This aproach will only work on a MP system , you could possibly acomplish
what you want ( responsive gui ) by using threading and create the worker
threads as lower prio background threads

Ofcourse will this result in longer processing time ( takes longer before
you app is finished )

regards

Michel Posseth [MCP]

"mark" <ma**@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
请考虑以下线程设置,以便在进行大量过程时释放UI

(声明代表) (AB和C全局)

私有子AB_Click(ByVal发送者As System.Object,ByVal e As
System.EventArgs)处理AB.Click
Dim NoArg1 As New NoArgs (AddressOf AxB)
NoArg1.BeginInvoke(Nothing,Nothing)
End Sub

私有子AxB()
Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
Dim AsyncResult由于IAsyncResult = mult.BeginInvoke(A,B,Nothing,
Nothing)
Do AsyncResult.IsCompleted
对于i = 1到1000000:Next:Button3.Text = Rnd()。ToString
循环
C = mult.EndInvoke(AsyncResult)
用C做其他东西结束Sub

Matrix_Multiply是班级求解者d使用超线程P4消耗50%的CPU资源。它是浮点算术密集型。当我运行
程序时,UI无法使用,直到最终的C结果 - 即
double(,) -
获得。 Button3.text最初显示活动但随后停止。
线程逻辑可以正常工作,只需运行一个循环
然后
返回一个字符串。

有什么问题?如何解决?
-
标记b
Please consider the following thread setup intended to free-up the UI
while a
huge process takes place:

(declare delegates) (A B and C all global)

Private Sub AB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AB.Click
Dim NoArg1 As New NoArgs(AddressOf AxB)
NoArg1.BeginInvoke(Nothing, Nothing)
End Sub

Private Sub AxB()
Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A, B, Nothing,
Nothing)
Do Until AsyncResult.IsCompleted
For i = 1 To 1000000 : Next : Button3.Text = Rnd().ToString
Loop
C = mult.EndInvoke(AsyncResult)
do other stuff with C
End Sub

Matrix_Multiply is the class solver and consumes 50% of CPU resources with
a
hyperthreading P4. It is floating point arithmatic intensive. When I run
the
program the UI is unavailable until the final C result - which is
double(,) -
is obtained. Button3.text initially shows activity but then stops. The
threading logic works fine with a local function that simply runs a loop
then
returns a string.

What''s wrong? How fix?
--
mark b






两者的答案都是肯定的。


MP是多处理器系统,是的,AMD / /
和英特尔现在出货的多核架构(在我看来) AMD的实现是优秀的,因为它可以作为一个真正的MP系统运行,因此解决了这个问题。


虽然如果它是您想要的响应性然后使用背景

线程选项可能仍然是一个好主意(虽然处理时间

可能需要更长的时间)

问候


Michel Posseth [MCP]


" mark" <毫安** @ discussions.microsoft.com> schreef in bericht

新闻:64 ********************************** @ microsof t.com ...

The answer to both is yes ,

MP is multi processor system , and yes the multicore architecture that AMD
and Intel are now shipping ( where in my opinion the AMD implemetation is
far superior ) would perform as a true MP system and so solve this
bottleneck problem .

Although if it is the responsiveness you want then using the background
thread option might still be a good idea ( although the processing time
might take a lot longer )
regards

Michel Posseth [MCP]

"mark" <ma**@discussions.microsoft.com> schreef in bericht
news:64**********************************@microsof t.com...

首字母缩略词MP是多处理器?如果是这样,您认为双核处理器可以做到吗?我已经考虑过内存访问的可能性
因为我的Matrix_multiply sub正在增加数组。

-
标记b

m.posseth写道:

The acronym MP is multiprocessor? If so, do you think dual core processors
can do it. I have considered the posibility that memory access is the
problem
as my Matrix_multiply sub is multiplying arrays.

--
mark b
"m.posseth" wrote:
你好Mark ,,,

这个aproach只适用于MP系统,你可能会
实现
什么你想要(响应gui)通过使用线程并创建工作线程作为较低的prio背景线程

当然会导致更长的处理时间(需要更长的时间才能使你的应用程序更新完成)

问候语Michel Posseth [MCP]

标记 <毫安** @ discussions.microsoft.com>在消息中写道
新闻:BB ********************************** @ microsof t.com。 ..
Hello Mark ,,,

This aproach will only work on a MP system , you could possibly
acomplish
what you want ( responsive gui ) by using threading and create the worker
threads as lower prio background threads

Ofcourse will this result in longer processing time ( takes longer before
you app is finished )

regards

Michel Posseth [MCP]

"mark" <ma**@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
>请考虑以下用于释放UI的线程设置
>而
>巨大的过程发生:
>
> (宣布代表)(A B和C全球)
>
> Private Sub AB_Click(ByVal sender As System.Object,ByVal e As
> System.EventArgs)处理AB.Click
> Dim NoArg1作为新NoArg(地址为AxB)
> NoArg1.BeginInvoke(没什么,没什么)
>结束子
>
>私人子AxB()
> Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
> Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A,B,
> Nothing,
> Nothing)
>直到AsyncResult.IsCompleted
>对于i = 1到1000000:下一个:Button3.Text = Rnd()。ToString
>循环
> C = mult.EndInvoke(AsyncResult)
>用C做其他事情
>结束子
>
> Matrix_Multiply是类求解器,消耗50%的CPU资源
>与
>
>超线程P4。它是浮点算术密集型。当我
>运行
>
>程序UI不可用,直到最终的C结果 - 这是
> double(,) -
>得到了。 Button3.text最初显示活动但随后停止。
>线程逻辑适用于只运行
>的本地函数。循环
>那么
>返回一个字符串。
>
>怎么了?如何解决?
> -
> mark b
> Please consider the following thread setup intended to free-up the UI
> while a
> huge process takes place:
>
> (declare delegates) (A B and C all global)
>
> Private Sub AB_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles AB.Click
> Dim NoArg1 As New NoArgs(AddressOf AxB)
> NoArg1.BeginInvoke(Nothing, Nothing)
> End Sub
>
> Private Sub AxB()
> Dim mult As New TwoArgs(AddressOf solver.Matrix_Multiply)
> Dim AsyncResult As IAsyncResult = mult.BeginInvoke(A, B,
> Nothing,
> Nothing)
> Do Until AsyncResult.IsCompleted
> For i = 1 To 1000000 : Next : Button3.Text = Rnd().ToString
> Loop
> C = mult.EndInvoke(AsyncResult)
> do other stuff with C
> End Sub
>
> Matrix_Multiply is the class solver and consumes 50% of CPU resources
> with
> a
> hyperthreading P4. It is floating point arithmatic intensive. When I
> run
> the
> program the UI is unavailable until the final C result - which is
> double(,) -
> is obtained. Button3.text initially shows activity but then stops. The
> threading logic works fine with a local function that simply runs a
> loop
> then
> returns a string.
>
> What''s wrong? How fix?
> --
> mark b




这篇关于异步线程没有释放UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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