Re: Do I need a mutex to access members from different threads?



On Jan 7, 7:53 am, Freesc <hjd.cl...@xxxxxxxxx> wrote:
On Jan 7, 2:03 am, mind_the_gap <2voo...@xxxxxx> wrote:

Hello there,

currently I am working on a c# project with the .Net Compact Framwork.
I have to use two threads where one of them modifies a member of the
class in regular timed intervals. The "normal" (e.g. the first or
start or main thread :P) thread needs to read this data to display it.
So can this bring up some errors or problems (like asyncronous reading/
writing) and do I need a mutex for writing and reading the data from
different threads?
Are there any examples for this? I am relatively new to threads.

Thanks in advance
Tom

 Control.Invoke() method will be a good choice ~

Thanks for the replys.
I tryed with events - the problem with this seems that the event code
is only run in the thread where it was fired - so in my case the
thread that changes the variable.
Or am I missing something. The solution with lock() seems to works - I
think I do this. But maybe I am missing something with those events.

Control.Invoke() can not be used as the "user" of the variable - the
class member using the variable and thus the class - does not extend
Control. This means I can not use this. It seems that lock() is the
keyword for non-control classes?

Thanks
.



Relevant Pages

  • Re: Do I need a mutex to access members from different threads?
    ... The lock keyword is simply a construct that gives a try ... writing) and do I need a mutex for writing and reading the data from ... But maybe I am missing something with those events. ...
    (microsoft.public.pocketpc.developer)
  • Re: When is "volatile" used instead of "lock" ?
    ... you're not asserting there can be no JIT optimizations of members ... lock { ... surrounding access to a member doesn't stop the compiler from having ... memory references can move to later than a volatile write or earlier ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: When is "volatile" used instead of "lock" ?
    ... The sample clearly shows that putting a member between Enter/Exit does not ... that only the locked object is the volatile ... Nah - I'll fix it just using an extra lock. ... uncomment the volatile on continueRunning and it runs as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Tasks: Assigned To list is incorrect--Help?
    ... The person who was missing from the list had Web ... WSS is on a FE web server ... > rid of the person who is not even a member of the site. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: New Berben Releases
    ... categories of composers, of course I did not refer to you in ... member of the category n. ... this in professional terms - as a music reader working for some ... publishers - and my duty would be accomplished with writing a report ...
    (rec.music.classical.guitar)