简体   繁体   English

第三方DLL引发事件

[英]3rd party dll raising events

I use a third party dll to get some data from their servers. 我使用第三方dll从其服务器获取一些数据。 There is a void method that I call and then i subscribe to an event raised by the call to this method. 我调用了一个void方法,然后我订阅了对此方法的调用引发的事件。 The event raised returns the data through its parameters. 引发的事件通过其参数返回数据。

so, call to : void getdata(id) raises: void onReturn(object) --> which returns an object that has the data. 因此,调用:void getdata(id)会引发:void onReturn(object)->返回具有数据的对象。

This WORKS everytime when there is a single call to getdata(id) 每当有一次对getdata(id)的调用时,此方法都起作用

The problem is when i loop through the list of ids, and inside that loop call getdata(id) for that list, the corresponding events are not raised properly. 问题是当我遍历id列表时,在该列表的循环调用getdata(id)内,相应的事件未正确引发。 Say for a list of 10 ids, there are 10 calls to getdata(id) but only few onReturns are raised. 假设有10个ID的列表,则有10个对getdata(id)的调用,但只引发了很少的onReturns。

The returned object also returns the id that was passed to getdata(id) so I can match the data i sent and the data that i receive. 返回的对象还返回传递给getdata(id)的id,以便我可以匹配发送的数据和接收的数据。

Is there a way to make sure that all events get listened to? 有没有办法确保所有事件都被监听? So if I send 10 ids by getdata(id), I want to make sure that the 10 onReturns are processed. 因此,如果我通过getdata(id)发送10个ID,则要确保已处理10个onReturns。

And i'm using c#, .net 4.0 我正在使用C#、. net 4.0

Thanks 谢谢

If it's a third party DLL, there's no telling how they've implemented it. 如果它是第三方DLL,则不会告诉他们它们是如何实现的。 When you step through in Debug mode, do you get past the call to getData() before the onReturn() listener is called? 当您进入调试模式时,是否在调用onReturn()侦听器之前onReturn()getData()的调用? If so, it might be using threads (or at least asynchronous listeners) internally, and calling multiple getData() s too close together might cause it to stomp on pending responses. 如果是这样,它可能在内部使用线程(或至少是异步侦听器),并且将多个getData()得太近可能会导致它在待处理的响应上脚。

The only way I could think to try and get around this is to use multithreading yourself, eg with a Mutex that waits after the call to getData() and releases in the onReturn() event. 我想尝试解决的唯一方法是自己使用多线程,例如使用Mutex,该Mutex在调用getData()之后等待并在onReturn()事件中释放。 This way you'd only have one outstanding request at a time, which seems to be the condition that works for you. 这样,您一次只会收到一个未解决的请求,这似乎是对您有效的条件。

Edit: Have you talked to the third party vendor about this yet? 编辑:您是否已经与第三方供应商讨论过此事? I'm guessing their support isn't the best if you thought of us first, but it might be worth a shot. 我想如果您首先想到我们,他们的支持并不是最好的,但是值得一试。

Edit the second: When you say it gets data from their servers, does this mean it makes requests over the network? 编辑第二个:当您说它从他们的服务器获取数据时,这是否意味着它通过网络发出请求? If those requests aren't encrypted, perhaps you could reverse engineer the protocol and make a new API for yourself instead of relying on a proven buggy black box. 如果这些请求未加密,那么您可以对协议进行反向工程并为自己创建一个新的API,而不必依赖经过验证的越野车。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM