从非托管C ++异步调用C#委托 [英] Invoke C# delegate asynchronously from unmanaged C++

查看:108
本文介绍了从非托管C ++异步调用C#委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以异步调用C#委托/事件处理程序,

来自非托管C ++?


我认为这需要一个托管C ++包装器,会在代表上打电话给

BeginInvoke吗?

这是否正确,若然,有没有人有例子?


谢谢!!

Is it possible to invoke a C# delegate/event handler asynchronously,
from unmanaged C++ ?

I assume this requires a Managed C++ wrapper, which would call
BeginInvoke on the delegate ?

Is this correct, and if so, does anyone have an example ?

Thanks !!

推荐答案

Yoni,


无法从非托管C中获取。要么必须使用

#pragma managed和#pragma unmanaged指令输入托管代码

并拨打电话,否则你必须将代表编组为函数

指针,在这种情况下你必须异步调用它,创建

你自己的线程等等。或者,你可以将类型导出为COM对象

并使用它,自己调用BeginInvoke方法。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- <小时EF = 电子邮件地址:NI ************** @ exisconsulting.com> NI ************** @ exisconsulting.com


" Yoni Rabinovitch" <哟************** @ adc.com>在消息中写道

news:d9 ************************** @ posting.google.c om ...
Yoni,

It is not possible from unmanaged C. You will either have to use the
#pragma managed and #pragma unmanaged directives to enter into managed code
and make the call, or you will have to marshal the delegate as a function
pointer, in which case you would have to call it asynchronously, creating
your own thread, etc, etc. Or, you could export the type as a COM object
and use that, calling the BeginInvoke method yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Yoni Rabinovitch" <yo**************@adc.com> wrote in message
news:d9**************************@posting.google.c om...
是否可以从非托管C ++中异步调用C#委托/事件处理程序?

我认为这需要一个托管C ++包装器,它将调用<委托上的BeginInvoke?

这是否正确,若然,有没有人有例子?

谢谢!!
Is it possible to invoke a C# delegate/event handler asynchronously,
from unmanaged C++ ?

I assume this requires a Managed C++ wrapper, which would call
BeginInvoke on the delegate ?

Is this correct, and if so, does anyone have an example ?

Thanks !!



Nicholas,也许我不理解你,


但是,我在做!


然而,我的应用程序在大约15分钟之后就崩溃了。


我担心因为我没有以任何方式锁定manged代码,

它被移动。

未管理的代码没有意识到这个变化,调用托管代码。

但是它使用了错误的地址。这会导致崩溃 -

ExecutionEngineException。


assaf


" ; Nicholas Paldino [.NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:eS ************* @ tk2msftngp13.phx.gbl ...
Nicholas, maybe i don''t understand you,

but, I''m doing it!

However, my app crashes after about 15 minutes of doing it intesively.

I fear that since i am not locking down the manged code in any way,
it gets moved around.
The Unmanaged code not being aware of this change, invokes the Managed code.
However it is using the wrong address. And this leads to a crash -
"ExecutionEngineException".

assaf


"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eS*************@tk2msftngp13.phx.gbl...
Yoni,

从无法管理的C是不可能的。你要么必须使用
#pragma managed和#pragma unmanaged指令输入托管的
代码并拨打电话,否则你将不得不将委托编组为函数指针,在这种情况下,您必须异步调用它,创建自己的线程等等。或者,您可以将类型导出为COM对象
并使用它,自己调用BeginInvoke方法。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP] - ni ************** @ exisconsulting.com

Yoni Rabinovitch <哟************** @ adc.com>在消息中写道
新闻:d9 ************************** @ posting.google.c om ...
Yoni,

It is not possible from unmanaged C. You will either have to use the
#pragma managed and #pragma unmanaged directives to enter into managed code and make the call, or you will have to marshal the delegate as a function
pointer, in which case you would have to call it asynchronously, creating
your own thread, etc, etc. Or, you could export the type as a COM object
and use that, calling the BeginInvoke method yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Yoni Rabinovitch" <yo**************@adc.com> wrote in message
news:d9**************************@posting.google.c om...
是否可以从非托管C ++中异步调用C#委托/事件处理程序?

我认为这需要一个托管C ++包装器,它将调用
BeginInvoke在代表身上?

这是否正确,如果有,有没有人有例子?

谢谢!
Is it possible to invoke a C# delegate/event handler asynchronously,
from unmanaged C++ ?

I assume this requires a Managed C++ wrapper, which would call
BeginInvoke on the delegate ?

Is this correct, and if so, does anyone have an example ?

Thanks !!




Assaf,


你是怎么做到的?你使用哪种方法?

-

- Nicholas Paldino [.NET / C#MVP]

- ni ************** @ exisconsulting.com


< as ***** @ hotmail.com>在消息中写道

新闻:ub ************** @ TK2MSFTNGP11.phx.gbl ...
Assaf,

How are you doing it? Which method are you using?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

<as*****@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP11.phx.gbl...
尼古拉斯,也许我不喜欢不理解你,

但是,我正在做这件事!

然而,我的应用程序在大约15分钟之后就会崩溃。

我担心因为我没有以任何方式锁定manged代码,
它会被移动。
非托管代码不知道这个更改,调用Managed
代码。但是它使用了错误的地址。这导致了崩溃 -
ExecutionEngineException。

Nicholas Paldino [.NET / C#MVP]" Nicholas Paldino < NI ************** @ exisconsulting.com>
在留言新闻中写道:eS ************* @ tk2msftngp13.phx.gbl ...
Nicholas, maybe i don''t understand you,

but, I''m doing it!

However, my app crashes after about 15 minutes of doing it intesively.

I fear that since i am not locking down the manged code in any way,
it gets moved around.
The Unmanaged code not being aware of this change, invokes the Managed code. However it is using the wrong address. And this leads to a crash -
"ExecutionEngineException".

assaf


"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:eS*************@tk2msftngp13.phx.gbl...
Yoni,

从非托管C开始是不可能的。你要么必须使用
#pragma managed和#pragma unmanaged指令进入托管
Yoni,

It is not possible from unmanaged C. You will either have to use the #pragma managed and #pragma unmanaged directives to enter into managed


代码

并制作调用,或者你必须将委托编组为
函数指针,在这种情况下你必须异步调用它,
创建你自己的线程等等。或者你可以导出键入COM
对象并使用它,自己调用BeginInvoke方法。

希望这会有所帮助。

-
- Nicholas Paldino [。 NET / C#MVP]
- ni *********** ***@exisconsulting.com

Yoni Rabinovitch <哟************** @ adc.com>在消息中写道
新闻:d9 ************************** @ posting.google.c om ...
and make the call, or you will have to marshal the delegate as a function pointer, in which case you would have to call it asynchronously, creating your own thread, etc, etc. Or, you could export the type as a COM object and use that, calling the BeginInvoke method yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Yoni Rabinovitch" <yo**************@adc.com> wrote in message
news:d9**************************@posting.google.c om...
是否可以从非托管C ++中异步调用C#委托/事件处理程序?

我认为这需要一个托管C ++包装器,它将调用
BeginInvoke在代表身上?

这是否正确,如果有,有没有人有例子?

谢谢!
Is it possible to invoke a C# delegate/event handler asynchronously,
from unmanaged C++ ?

I assume this requires a Managed C++ wrapper, which would call
BeginInvoke on the delegate ?

Is this correct, and if so, does anyone have an example ?

Thanks !!





这篇关于从非托管C ++异步调用C#委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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