Author |
Topic: OECapi inside a DLL (No UI thread) (7 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
MFrasson3344 Posts: 45 Joined: Nov 09, 2015 |
Hello,
i'm tring to use OECapi client inside a DLL on a different thread (not the UI), but it does not work. It works only if i use the API in the UI (user interface) thread. It is correct? or where could be the problem? Thanks Mauro frasson |
||||
VPfau Moderator Posts: 164 Joined: |
Hello Mauro,
our documentation (http://futures.gaincapital.com/api/api/index.html) describes your situation in FAQ section Quote: I’ve started OECAPI in console application and do not receive any events. Why? Thread that created OEC.API.OECClient should have Windows message pump. WinForms applications have the pump implicitly in the main UI thread. Also there Getting Started\Connect to OEC section with console sample which could be helpful for you. Vitaliy Pfau |
||||
MFrasson3344 Posts: 45 Joined: Nov 09, 2015 |
Really is there no way to bypass the UI thread? if no i have to build a separate exe and then use a pipe to comunicate with main program.. and it is horrible!
Mauro frasson Edited by MFrasson3344 on Jan 26, 2016 at 13:51:05 Edited by MFrasson3344 on Jan 26, 2016 at 13:51:36 |
||||
VPfau Moderator Posts: 164 Joined: |
You don't have to "build a separate exe" and communicate with main program. OECAPI uses standard windows message pump for events delivery. You can start it without any UI thread.
Please follow links I posted. Vitaliy Pfau |
||||
MFrasson3344 Posts: 45 Joined: Nov 09, 2015 |
Ok, sorry. I try to explain better. I used the wrong word "UI", but "UI" means "the main thread".
So the situation is this: 1) I have a main thread 2) I have a lot of secondary tasks/threads 3) one of these threads create an instance using a class placed on a separate DLL. 4) into this class i create the OECapi client. The problem is that the thread where i create the client is not the main thread so i do not receive the events. Mauro frasson |
||||
VPfau Moderator Posts: 164 Joined: |
Here is couple ways to solve your issue:
1. you are going to run windows message pump and receive messages there, then, if needed, post them to your thread. For example from main thread:
2. Create OECClient with ThreadPolicy
this is undocumented ability and you accept risks using this. All incoming events will go thru Send\Post functions of threading policy. Be careful, blocking the thread from Send\Post functions for a long time will result slow connection disconnect. So, to avoid slow connection disconnects you need pump messages whatever way you choose. I think it is better use a standard supported method. Vitaliy Pfau |
||||
MFrasson3344 Posts: 45 Joined: Nov 09, 2015 |
Ok thank you.
I think i'll run a secondary thread from my class using your first solution. Mauro frasson |
||||