By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

interlock problem

P: n/a
Hi
I have Download form, that starts Download file thread which uses
interlocked Stop variable to stop thread when Dispose will set Stop to true;
bool nExit;
readonly object exitLock = new object();
bool NormalExit
{
get
{
lock (exitLock)
{
return nExit;
}
}
set
{
lock (exitLock)
{
nExit = value;
}
}
}

When i start another instance od Download form, and experiment with closing
one of them, it seems that one Download instance is acting in some way on
another. It looks like they share Stop variable or somthing. I tried to
figure it out for long time but without any effect. Sometimes when i Dispose
one instance od Download it freezes anouter instances.
I heard that shared variables are only static variables.
And one more:
This download thread is checking for Close variable in Download while loop.
Thanks for any help
PK
Sep 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
PiotrKolodziej <pi*************@gmail.comwrote:
I have Download form, that starts Download file thread which uses
interlocked Stop variable to stop thread when Dispose will set Stop to true;
bool nExit;
readonly object exitLock = new object();
bool NormalExit
{
get
{
lock (exitLock)
{
return nExit;
}
}
set
{
lock (exitLock)
{
nExit = value;
}
}
}
Well, that bit of code looks okay.
When i start another instance od Download form, and experiment with closing
one of them, it seems that one Download instance is acting in some way on
another.
If the code is as you've posted, it should be fine. Are you sure you
don't have the "nExit" variable static in your code? Or perhaps the
close event handler in one is hooked up to the close event of the
other?
It looks like they share Stop variable or somthing. I tried to
figure it out for long time but without any effect. Sometimes when i Dispose
one instance od Download it freezes anouter instances.
I heard that shared variables are only static variables.
And one more:
This download thread is checking for Close variable in Download while loop.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 27 '06 #2

P: n/a
The problem seemed to be Thread.Join(). But thank you for your post. Now iam
sure everything is okay.
PK
Sep 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.