RE: Thread.Monitor & references
From: Ansil MCAD (AnsilMCAD_at_discussions.microsoft.com)
Date: 10/05/04
- Next message: Elhanan maayan: "stay in vb6, or move to csharp?"
- Previous message: Ken Arway: "Re: Using a regular expression to parse comments from aspx (ASP.NET) files"
- In reply to: Brett Robichaud: "Thread.Monitor & references"
- Next in thread: Bruno Jouhier [MVP]: "Re: Thread.Monitor & references"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 4 Oct 2004 20:37:01 -0700
hi
you can either use lock block or Mutex itself
regards
ansil
"Brett Robichaud" wrote:
> I need to make access to a reference object threadsafe. My natural instinct
> was to simply use Monitor.Enter() and Exit(). The problem is that the
> object behind the reference changes frequently, so my understanding of
> Monitor indicates this would not protect my object. Example:
>
> Bitmap bmp = new Bitmap("x.jpg");
> Monitor.Enter(bmp);
> bmp = new Bitmap("y.jpg");
> Monitor.Exit(bmp);
>
> The above doesn't do when one might expect, correct? My C++ head says to me
> that what I really want to do is protect the 'pointer', not thing 'thing
> pointed to', since I have no other pointers to this thing. But I'm in C# now
> and my head is baffled.
>
> So currently I am using a Mutex to protect this kind of data, but it seems
> more klunky. Is there any way to use the slick Monitor (or lock) syntax and
> still protect this situation?
>
> -Brett-
>
>
>
- Next message: Elhanan maayan: "stay in vb6, or move to csharp?"
- Previous message: Ken Arway: "Re: Using a regular expression to parse comments from aspx (ASP.NET) files"
- In reply to: Brett Robichaud: "Thread.Monitor & references"
- Next in thread: Bruno Jouhier [MVP]: "Re: Thread.Monitor & references"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|