Author |
Topic: OECClient in other thread (7 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
VVadim41 Posts: 12 Joined: Mar 22, 2010 |
Hello.
I'm writing my programm and I want to add OECClient in other thread. I trying to do something like code on bottom, but callbacks not works... I try use waitHandle.WaitOne and this not works too... Can you help me with idea? ps on Main thread all works good of caurse...
|
||||
VictorV Posts: 746 Joined: May 08, 2007 |
Hello,
You need to add Windows message pump to your non-main thread with OECAPI. Victor Vins Software Developer |
||||
VVadim41 Posts: 12 Joined: Mar 22, 2010 |
very strange method.
Are there any other way, more elegant? |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
OECAPI is based on Windows messages.
Victor Vins Software Developer |
||||
JBerrojalbiz381 Posts: 9 Joined: Apr 06, 2011 |
Hi Victor,
Could you provide some advice or code sample for doing this? >> "You need to add Windows message pump to your non-main thread with OECAPI" Thanks in advance, Jon. Jon Berrojalbiz |
||||
THarnett81 Posts: 78 Joined: Jan 13, 2011 |
In C# WPF, the callbacks will occur on the UI event thread. You have to ensure that any UI event handlers do not block, else all your OEC events will queue until your UI event lets go.
See this thread: http://www.openecry.com/cfbb/index.cfm?page=topic&topicID=497 |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
Hello,
message pump should look like: class Program { static void Main(string[] args) { var thread = new Thread(OecApartment) { Name = "OECThread" }; thread.Start(); Console.ReadLine(); } static void OecApartment(object state) { OECClient client = new OECClient(); client.OnLoginComplete += new OnLoginCompleteEvent(client_OnLoginComplete); client.Connect("api.openecry.com", 9200, "usr", "pwd", false); while (true) { System.Threading.Thread.Sleep(1); System.Windows.Forms.Application.DoEvents(); } } static void client_OnLoginComplete() { Console.WriteLine("Hi there! Current thread: {0}", Thread.CurrentThread.Name); } } Victor Vins Software Developer |
||||