Author |
Topic: OnLoginComplete event doesn't fire (6 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
THarnett81 Posts: 78 Joined: Jan 13, 2011 |
I'm trying to get a simple console app working. I'm looking at your example code, and it seems very simple, but I can't figure out where I'm going wrong.
OEC.API.OECClient _oec = new OEC.API.OECClient(); _oec.OnLoginComplete += new OEC.API.OnLoginCompleteEvent(this.cb_OnLoginComplete); Console.WriteLine("Attempting to connect..."); _oec.Connect("api.openecry.com", 9200, "<username>", "<password>", false); Console.WriteLine("Server found. Waiting for connection complete."); Thread.Sleep(100*1000); During that sleep, I expect OnLoginComplete to fire, and it never happens. I also have handlers on OnDisconnected, OnLoginFailed, OnError, and OnUserEvent. None of these events fire. I can run "OEC API Example" with the same login, and the procedure finishes correctly. I've stepped through the code, but for the life of me, I can't figure out what the example is doing that I am not. Thanks for any help. Edited by THarnett81 on Mar 31, 2011 at 22:18:56 |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
Hello,
OECAPI fires event via Windows messages behind scene. You need to start some message pump in the thread that created the instance of OECAPI. Victor Vins Software Developer |
||||
THarnett81 Posts: 78 Joined: Jan 13, 2011 |
I've been doing some Googling, and this seems non-trivial. Or, at least, I've not been able to find a simple example of this.
Does anyone have an example of how to do this? Surely I'm not the first person to attempt to use OEC in a console application or a WPF application. Edited by THarnett81 on Apr 1, 2011 at 09:52:36 |
||||
THarnett81 Posts: 78 Joined: Jan 13, 2011 |
Ah, I got it now.
My trouble wasn't WPF vs WinForms, it was UI vs Console. If you use the OEC lib in a console app, the OEC events don't trigger. I don't know where the events go, but they sure don't go to your app. As VictorV said, for a console app you'll need to start a message pump or something. I don't know much Windows programming outside of WPF/C#, so I wasn't able to figure that out. Luckily, I don't really need a console app. I whipped up a demo WPF app, and WPF magically does the behind-the-scenes message pump bullcrap. Ironically, I started with the console app because I thought it would be the easiest way to demo basic functionality of the OEC library. How backwards is it when a UI app is easier than a console app? Edited by THarnett81 on Apr 1, 2011 at 14:07:37 |
||||
ZKurmas Posts: 1 Joined: Apr 12, 2011 |
My long-term goal is to run the strategy on a servers somewhere (as opposed to my PC at home). Does this console event issue mean that the OEC API is not a good platform for me?
Zachary Kurmas |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
Hello,
Windows message pump can be started virtually in any kind of .NET application. Please check System.Windows.Forms .Application.DoEvents() method. Victor Vins Software Developer |
||||