取消事件,然后从该事件调用的子例程中进一步执行该事件. [英] Cancel a Event and it's further execution from a Subroutine called from that event.
问题描述
首先,我将解释我的要求:
First I will explain my requirement:
请考虑以下代码段.
Private Sub SomeEvent(Byval sender as Object) Handles SomeControl.SomeEvent
--Do Something_1
--Do Something_2
--Do Something_3
call A()
--Do Something_4
--Do Something_5
--Do Something_6
End Sub
Private Sub Procedure_A ()
--Do Something_1
--Do Something_2
--Do Something_3
call B()
--Do Something_4
--Do Something_5
--Do Something_6
End Sub
Private Sub Procedure_B ()
--Do Something_1
--Do Something_2
--Do Something_3
'Exception Ocurs...Here
--Do Something_4
--Do Something_5
--Do Something_6
End Sub
在上述异常中,如果该异常发生在Procedure_B中的上述位置,则
In the above exception, if the exception occurs at the said location in Procedure_B then,
1. Procedure_B中的其余语句不应执行.
1. Remaining Statements in Procedure_B should not execute.
2. Procedure_A中的其余语句不应执行.
2. Remaining Statements in Procedure_A should not execute.
3. SomeEvent中的其余语句不应执行.
3. Remaining Statements in SomeEvent should not execute.
请不要这样:
我知道这可以通过在每个子例程中使用Try..Catch并从此处引发异常来处理.但是由于某种原因无法实现.
I know this can be handled by using Try..Catch in every Subroutine and Raise an exception from there. But it cannot be implemented due to some reason.
我正在寻找的解决方案是
The solution I am looking for is
1.要以某种方式取消SomeEvent已启动的ProcessThread.
1. To somehow cancel the ProcessThread the SomeEvent has started.
或
2.如果我可以以编程方式设置下一条语句
2. If I could programatically Set Next Statement
推荐答案
我认为您只需要尝试捕获 SomeEvent ,而不是在每个过程中:
I think that you only need Try-Catch in SomeEvent, not in every procedure:
-做某事_1
-做某事_2
-做某事_3
尝试
致电A()
-做某事_4
-做某事_5
-做某事_6
捕获
结束尝试
--Do Something_1
--Do Something_2
--Do Something_3
Try
Call A()
--Do Something_4
--Do Something_5
--Do Something_6
Catch
End Try
还可以区分特定的例外.
It is also possible to distinguish specific exceptions.
不清楚为什么您不能使用 Try-Catch.然后使用 出现错误时:
It is not clear why you cannot use Try-Catch. Then use On Error instead:
-做某事_1
-做某事_2
-做某事_3
出现错误时转到错误1
致电A()
-做某事_4
-做某事_5
-做某事_6
返回
错误1:
...
--Do Something_1
--Do Something_2
--Do Something_3
On Error GoTo Error1
Call A()
--Do Something_4
--Do Something_5
--Do Something_6
Return
Error1:
…
这篇关于取消事件,然后从该事件调用的子例程中进一步执行该事件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!