Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,614 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 952 people online right now. Registration is fast and FREE... Join Now!




Updating buffer with background worker

 
Reply to this topicStart new topic

Updating buffer with background worker

killnine
post 9 Jul, 2008 - 01:12 PM
Post #1


D.I.C Head

**
Joined: 12 Feb, 2007
Posts: 107



Thanked 3 times
My Contributions


Hey guys,
Lots of questions lately, right?

Anyhow, I am creating a program that collects data from a system at a high rate of speed (think 24 doubles at 10ms/100hz). What I am trying to do is create a buffer to store a timestamp and 24 signals.

Right now I am creating an array of 25 doubles. THEN I put that array into a List<double[]>. I repeat this process at 10ms intervals until my user interface grabs the buffer, displays it on the screen (via ZedGraph) and clears the buffer.

However, I am running into the problem where I can EITHER update the buffer or update the graph: not both. So I get these huge gaps in my data (100ms+) while the system updates the UI.

I think a background worker would be useful here. But my question is really this: can I update my buffer periodically, and still access/clear it from the UI thread? I don't think I can, but how else could I solve this problem? Yikes!
User is offlineProfile CardPM

Go to the top of the page

zakary
post 10 Jul, 2008 - 03:35 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 401



Thanked 6 times

Dream Kudos: 175
My Contributions


you can you just need to invoke the update method when you want it to update
User is offlineProfile CardPM

Go to the top of the page

killnine
post 10 Jul, 2008 - 04:59 AM
Post #3


D.I.C Head

**
Joined: 12 Feb, 2007
Posts: 107



Thanked 3 times
My Contributions


QUOTE(zakary @ 10 Jul, 2008 - 04:35 AM) *

you can you just need to invoke the update method when you want it to update


I ended up throwing the 5ms loop into a background worker and accessed the List on the UI thread. It works fine.

I thought I was going to have a problem with crossthreading, but it doesn't seem to be an issue. Cool. =)
User is offlineProfile CardPM

Go to the top of the page

zakary
post 10 Jul, 2008 - 05:09 AM
Post #4


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 401



Thanked 6 times

Dream Kudos: 175
My Contributions


If you start to have problems with crosstreading what you can do is use a Lock(this) {}. this will lock the section you are having problems with for a short time and normally the user will not see this or be effected by it.
User is offlineProfile CardPM

Go to the top of the page

killnine
post 11 Jul, 2008 - 06:42 AM
Post #5


D.I.C Head

**
Joined: 12 Feb, 2007
Posts: 107



Thanked 3 times
My Contributions


QUOTE(zakary @ 10 Jul, 2008 - 06:09 AM) *

If you start to have problems with crosstreading what you can do is use a Lock(this) {}. this will lock the section you are having problems with for a short time and normally the user will not see this or be effected by it.



Ah yes, lock can be used.

I have used that function in the past with great success. I sorta forgot about it tongue.gif

No problems reported as of yet....::crosses fingers::
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:49AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month