newby on threads

S

Steve

Hi,

I have a background thread which can periodically update a file. My actions
in the UI thread can also update this file (using xmldocument.save()). Is
there an easy way to makesure that when something has the file open nothing
else can and must wait its turn.

I've tried having a global object (object x = new object) and tried locking
this ( lock (x) {..file access stuff} ) but gets some deadlock problem.

I've also tried setting a global bool when I start file access stuff and
tried waiting until it gets reset but my background thread doesn't appear to
set it right.

Are there any simple tutorials out there for this kind of thing as my
initial look at threads are confusing and I'm sure I'm going at this in the
wrong way.

thanks in advance. I understand this may not be the right place for this
question but I believe the .CF is limited on its thread functionality -
hence why I'm here.

Steve
 
G

Guest

The theory here is the same as in the desktop, as well as any language.
Your best bet is to create methods or even a class, that controls all acess
to the file, then use a thread sync object, like Monitor or lock, inside
that to serialize all file access. If you need to lock during a write that
prevents on the reads *and* writes, then it's mroe complex and will require
a Mutex, but the same principal applies.
 
S

Steve

Thanks for the advice. I was using lock around the method but switched to
using monitor and this works really well. Not sure why the difference but
whatever works at this point.

thanks again for the feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top