Profile Picture

Called AddOutputLine from wrong thread

Posted By takacsg84 5 Years Ago
Message
Posted Thursday October 18 2012
I`m running a consistency check every minute in my trading system. For this i`m using Threading.Timer class (since it was the only timer it was working) which calls my method from another thread then the main thread (where the Forms of RightEdge where created). Though the other thread is live for a very short time, it sometimes still happens that RightEdge wants to write something to the output at the exact same moment. The result of this is a following exception:
Called AddOutputLine from wrong thread
at RightEdge.OutputPane.AddOutputLine(SystemOutput systemOutput, Boolean ensureVisible)
at RightEdge.xf266856f631ec016.xe76263e9c29b08f6(Object xe0292b9ed599da7d, SystemOutputEventArgs e)

Any suggestions on how to handle this?
One basic idea would be to user Forms.Timer class instead of Threading.Timer, but for some reason it is not working with RightEdge...
Posted Thursday October 18 2012
Use the SystemData.SynchronizationContext property to switch back to the system thread, by calling the Post or Send methods. Post will return immediately, while Send will wait for the operation to complete before continuing on the thread that called it.

Generally you shouldn't interact with any system objects on another thread. If you are using a timer, then you should Post a message back to the main thread and do all your work in that thread.

Let us know if you need more details on how to accomplish this.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems