From: Dave C. <dav...@gm...> - 2008-03-13 15:22:37
|
MT, Cross thread UI interaction is a big headache I've found. I've since moved from using the Form thread timer to a System.Threading.Timer. This way I can have an intermediate object receive events from the environment (tick server) and then build OHLC bars there. A form (or whatever object that needs to consume bars - 1 second, 5 second, 1 minute, etc.) requests a certain periodicity from the barbuilder object. This object then creates a Threading timer which emits bars at the specified interval. The form then consumes those events, saves the bars in a cache (datatable) and on that event repaints the graph. The problem of course is that this object's Threading timer thread is cross threaded from the form. And so I must perform a this.InvokeRequired test and use that method delegate: if (this.InvokeRequired) { this.Invoke(new MethodInvoker(ProcessLatestQuote)); return; } Even so, I'm getting what appear to be cross thread lockups at update frequencies of 2 seconds or less. So I'm thinking that in order to avoid these lockups I must do nothing aside from update a local cache of quotes on the Threading timer event - and get out fast. And then to lock(cache) {} while I perform a graph update. Sorry if this appears off-topic for this list. But the concept of graph updates on timers and cross threading is an issue that many will encounter when using NPlot to graph real time data. Regards, Dave Cline On Thu, Mar 13, 2008 at 6:44 AM, MT <mt...@ya...> wrote: > Thanks Dave, > > That example worked great for me. My mistake was to use System.Timers.Timer instead of Windows.Forms.Timer. System.Timers.Timer executes on an arbitrary thread which was the source of my problem I think. > -- ___________________ Dav...@gm... www.davecline.com Lake Oswego, OR 801-473-9213 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ |