初始化/声明代表 [英] Initalizing / declaring Delegates

查看:93
本文介绍了初始化/声明代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是一个愚蠢的问题,但我认为我最好与专家确认:-)

过去,我在一个单独的模块中初始化/声明了委托,从而使他们可以在整个解决方案中访问


Probably A stupid question but I think I better check with the experts :-)

In the past I have initialized/ declared delegates in a separate module making them accessible throughout the whole solution


Delegate Delegate_NO_parameter()




然后,我在代码中的很多地方(不同的模块/表单)一直使用 same 委托




Then, I have been using this same delegate in numerous places in my code (different modules / forms)

Sub 1 ()
   Dim d As New Delegate_NO_parameter(AddressOf X) 
   Me.Invoke(d)
End sub

Sub 2 ()
   Dim d As New Delegate_NO_parameter(AddressOf Y) 
   Me.Invoke(d)
End sub




现在我知道这可能不是这样做的正确方法,但是到目前为止,我从未遇到过麻烦-直到现在...

这样做是否有可能使回调函数得到交叉引用=而不是调用 Sub X ,如果两者都在相同时间
我认为它不应该-但是在我的代码中,我仅通过移动"类似的回调就可以解决几天来困扰我的问题?




Now I know this might not be the proper way of doing so but so fare I''ve never had an issue with it - until now ...

Is it possible that by doing so, the callback''s could get cross referenced = instead of calling Sub X it might call Sub Y if both get invoked at the "same" Time
I don''t think it should - but in my code I was able to fix an issue that has been bugging me for days by just "moving" similar callbacks around a bit ???

推荐答案

什么是代表?

http://www.developerfusion.com/article/5251/delegates-in-vbnet/ [ ^ ]
What are Delegates?

http://www.developerfusion.com/article/5251/delegates-in-vbnet/[^]


我搞砸了-我的工作线程中的timer_tick搞砸了全局变量
=移动代码只是改变了时间=导致结果不一致

-我将像过去一样继续使用代理人:-)

乔治
I messed up -a timer_tick in my worker thread was messing with a global variable
= moving code around just changed the timing = resulting in inconstant results

- I''ll keep using delegates as I have in the past :-)

Georg


这篇关于初始化/声明代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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