|
What version of .NET ? Why don't you have IIS ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I've been programming under the assumption that taking a lock out on an object will get an exclusive lock out, so no other thread can enter any region that uses the same object as a lock.
i.e.
<br />
void Read()<br />
{<br />
lock(obj)<br />
{<br />
}<br />
}<br />
<br />
void Write(data)<br />
{<br />
lock(obj)<br />
{<br />
}<br />
}<br />
Now i was thinking that a synronous call to Read and Write would lock 'obj' and prevent two threads from
doing different things at the same time.
However, while debugging an app (That i had tested with numerous multi threaded scenarios and had no problems), i found that i could have a breakpoint in Read and a breakpoint in write, and they would hit alternatively, while there was still logic to be executed in both blocks. This has made me wonder whether i'm totaly wrong about the whole locking mechanism and whether a lock is only obtained for a particular region of code, rather than the object itself.
Alternativly, could this be an issue with Debugging and stepping through multi threaded apps?
Can anyone shed any light on the subject please?
Cheers
Tristan RHodes
|
|
|
|
|
The Catalyst wrote: Now i was thinking that a synronous call to Read and Write would lock 'obj' and prevent two threads from
doing different things at the same time.
That's correct. Only one thread can be running the code inside Read/Write at any point in time (assuming they're sharing the locked object obj )
The Catalyst wrote: However, while debugging an app (That i had tested with numerous multi threaded scenarios and had no problems), i found that i could have a breakpoint in Read and a breakpoint in write, and they would hit alternatively, while there was still logic to be executed in both blocks.
Where did you put the breakpoint? The breakpoint would hit the lock statement, but would block if you try to execute the thread.
The Catalyst wrote: whether a lock is only obtained for a particular region of code, rather than the object itself.
Now that's confusing. The lock does not lock the object passed to the lock statement, it only uses the object as a kind of token to indicate the thing this thread should lock on.
|
|
|
|
|
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite classes Point3, Circle4 and Cylinder to use composition, rather than inheritance. After you do this, assess the relative merits of the two approaches for both the Point3, Circle4, Cylinder problem, as well as for object-oriented programs in general. Which approach is more natural, why?
is he here want one in inheritance and one without inheritance ????
am i right
thanks
|
|
|
|
|
Yes, he wants one of each.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi,
Im developing an app like a Image Manager, using database, categories, nodes, etc...
Now I have to put the images in a ListView, I will retrieve the list of images from the Database and try to show them on the LargeIconsView, I tried to search something about it to do it in the right way, but no luck by the moment.
And im thinking to thumbnalize the images ( due they are like 14-22MB ) and place them in a indexed ImageList to show them.
Am I getting the right way ?
Many thanx in advance,
|
|
|
|
|
Yes, that would be the way to go.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thanx mate,
Then time to precache, thumbanilze, and optimize a good ImageList, a find out how to serialize it to the HDD.
Thanx again for your reply,
|
|
|
|
|
Just out of sick curiosity, is there a function in the .NET Framework that I can call that is guaranteed to block forever? Right now I'm creating a new ManualResetEvent object, then calling its WaitOne() method.
The reason for this is that I'm calling a ton of Stream.BeginRead() methods from my Main() method, and the delegates called when these reads complete eventually take over program execution. I'm pretty sure that this is bad coding style, but this is just for an experimental application, not a production app.
Thanks!
|
|
|
|
|
public void NeverExit()
{
while (true)
;
}
? What was so difficult?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Well, yeah - but I was hoping for something that didn't burn clock cycles like mad. My program *does* have other threads doing real work, after all.
Like I said, this is strictly an academic exercise for my own sake. If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives.
BTW, I also thought of using Thread.Suspend(), but unfortunately it has been deprecated.
|
|
|
|
|
So, throw a Thread.Sleep(10) in the while loop.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Vega02 wrote: If indefinitely suspending the Main() thread is the wrong way of going about this, I'm certainly open to alternatives.
You mean like blocking on an Event until another thread signals it?
led mike
|
|
|
|
|
Well, yeah, but in my case no other thread will ever signal it. Creating a ManualResetEvent and waiting on it to perform an indefinite block - something just feels wrong about doing that.
|
|
|
|
|
As mentioned below Thread.Sleep(Timeout.Infinite) is what you want.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
while (1 == 1)
{
}
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thread.Sleep(Infinite);
---
b { font-weight: normal; }
|
|
|
|
|
Of course! I had completely forgotten about that.
Thanks
|
|
|
|
|
When a user Clicks on an area of the listview that is not an item, the listview loses the selecteditem. How would I prevent this. Thanks in advance for assistance.
|
|
|
|
|
You'd have to derive a class from the listview, I would guess.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You can reselect it in the SelectedIndexChanged event, or the Click /MouseClick /MouseDoubleClick events.
Regards
|
|
|
|
|
Hi,
can any one have a source code for applying curves (curvature ) on image to smooth it?
i work in the implementation of (Interactive Algorithm For Image Smoothing and Segmentation) and i need to smooth the image by curvature as a pre-processing stage befor the segmentation.
thanks,
|
|
|
|
|
fcis2007 wrote: can any one have a source code for applying curves (curvature ) on image to smooth it?
How do you mean ? My image processing articles have a convolution filter for smoothing ( a pretty standard one, I doubt it's what you want ). How do you 'apply curves' to an image ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Are you talking about curves, like photoshop?
|
|
|
|
|
this application will explain what i mean...
on the following link:
www.smalleranimals.com/isource.htm#download
you will find the folder:
ISource40.zip
when openning and running the application ... you will found the function number [5] "Curves" ,So see the effect on the image after check "Apply Curves" checkbox and choose 32 step from the combo box
my aim is obtain the code of this function to control the number of steps and hence control the degree of smoothing of my image.
about the question of Why using this methode exactlly...
I use it because it is a pre_processing stage for smoothing the image in order to implementation of ISS algorithm "Interactive Algorithm For Image Smoothing And Segmentation"
thanks,
|
|
|
|