回调/委托?
我有一个疑问..
我想创建一个函数,它看起来像这样...
public class A //this is just a class file
{
function dowork()
{
//work 1
INPUT = here in this line it should call a delegate function or raise event etc...
//work 2 using INPUT
}
}
public class B
{
function myfn()
{
A objA = new A();
objA.dowork();
}
}
在“A类”中,我们将引发事件左右&它将向用户显示一个窗口窗体,然后用户将输入一些值&我们需要将该值返回给 A 类 -> dowork 方法...那么只有我们应该继续“work 2”,
这也应该支持多线程...任何人都知道我们如何实现这个?
谢谢 :)
i have a doubt..
i would like to create a function and it will look like this...
public class A //this is just a class file
{
function dowork()
{
//work 1
INPUT = here in this line it should call a delegate function or raise event etc...
//work 2 using INPUT
}
}
public class B
{
function myfn()
{
A objA = new A();
objA.dowork();
}
}
In the "Class A" we will raise event or so & it will display a windows form to user and then user will input some value & we need to return that value to Class A -> dowork method.... then only we should continue "work 2"
this should also support multi threading... anyone have idea how we can implement this??
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ManulResetEvent 达到此目的:您运行输入表单,完成后该表单设置事件,以便您可以从 A.dowork 方法捕获它。当输入运行时,您运行无限循环,检查事件状态并处理应用程序事件,以使您的应用程序在此时负责:
另外,我建议您(如果可以)使用异步库(它可作为独立设置使用)。在那里,您可以以更直接的方式实现它:
正如您所看到的,您只需等待其他代码片段的执行,而无需任何 UI 锁定和事件。
如果您需要,我可以在这里提供有关异步/等待如何工作的更深入的解释。
You can use ManulResetEvent for this purpose: You run your input form and when it done that form set the event so you can catch it from A.dowork method. While the input in action you run the infinite loop, check event state and process application event to make you app responsible in this time:
Also, I suggest you (if you can) use Async library (it is available as a standalone setup). There you can implement it in much more straightforward way:
As you see you just wait while other piece of code get executed without any UI locking and events.
I can provide deeper explanation of how async/wait works here if you need.