interlock problem

  • Thread starter Thread starter PiotrKolodziej
  • Start date Start date
P

PiotrKolodziej

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
 
PiotrKolodziej said:
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.
 
The problem seemed to be Thread.Join(). But thank you for your post. Now iam
sure everything is okay.
PK
 

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

Back
Top