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

race condition?

P: n/a
I wouldn't nomally post this here, as it has something to do with the
ListView control usage I think, or maybe with a race condition or some
windoes messaging. I'm just not sure.

The test below succeeds IF i walk through the debugger and IF I examine the
ListViewItem's properties in the debugger visualizer. Otherwise, it fails.
Any ideas?

Thanks. BH

[Test]
public void SelectedItem_ReturnsFirstTheSelectectedItem() {
_addData();
Assert.That(_listView.Items.Count, Is.GreaterThan(0), "Data added
test");

var listViewItem = _listView.Items[0];
Assert.That(listViewItem, Is.Not.Null);
_listView.Focus();

listViewItem.Selected = true; ---------------XX only if in debug

Assert.That(_listView.SelectedItems.Count, Is.GreaterThan(0), "ListView
not responding to Selected=true");----xx---only if in debug

Assert.That(_widget.SelectedItem, Is.Not.Null, "Point of the test!");
}
Oct 26 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Sun, 26 Oct 2008 13:27:20 -0700, Berryl Hesh <ef******@yahoo.comwrote:
I wouldn't nomally post this here, as it has something to do with the
ListView control usage I think, or maybe with a race condition or some
windoes messaging. I'm just not sure.
A race condition requires more than one thread. Do you have a second
thread?

You've only posted a single method, which by itself isn't nearly enough to
illustrate a specific problem, never mind a race condition. At a minimum,
you need to more completely describe the code involved here, and really
you should post a concise-but-complete code example that reliably
demonstrates the problem.

I can certainly imagine that if you're calling that code from a thread
other than the one that owns the control, you _might_ get the behavior
you're observing. But speculating isn't a very useful way to debug code.

Pete
Oct 26 '08 #2

P: n/a
I don't know the ListView control very well, at all which is part of the
problem, and I've already debugged this to the best of my current ability. I
was hoping by posting here I could get help in isolating the problem enough
to fix it, or find out I'm not using the ListView control correctly.

The test method I posted earlier is being invoked by a TestRunner, I assume.
I am not explicitly creating any other threads.

There class I am testing here is a wrapper around the ListView control
called ListViewLookupWrapper. It's code and inheritance chain is below. One
of the features of the class is to allow the SelectedIndexChanged event to
be delegated as nessary to some method outside of a windows form, where it
can be tested more easily (I have other tests showing that this scheme works
with and without a listView implementation). Another is to capture the
selected item as an ILookupDTO implementation - it is this SelectedItem
method that I'm trying to test. To do that I want to trigger the listview's
own SelectedIndexChanged event. I'm not doing anything with the event here
beyond trying to trigger it, just counting on the ListView to fulfill it's
contract and have the selected item available in it's own SelectedItems
property.

That's where I get to my previous post, as I can't yet prove or disprove
what's going on with the event firing in the debugger after I examine it,
but not otherwise.

Cheers, and thanks for sharing. BH

--------------------------------------------------------------------------------------

public class ListViewLookupWrapper : LookupListBase
{
protected readonly ListView _listView;
public ListViewLookupWrapper(ListView underlyingList) {
_listView = underlyingList;
_ listView.SelectedIndexChanged +=
OnSelectedIndexChanged; -<--XX----- the parent exposes this as a property
}

public override void Add(ILookupDTO lookupDto) {...}
public override void Clear() { _listView.Items.Clear(); }

public override ILookupDTO SelectedItem {
get {
if (_listView.SelectedItems.Count 0) {
var listViewItem = _listView.SelectedItems[0];
var item = new
SimpleLookupDTO(listViewItem.SubItems[0].Text, listViewItem.Text);
return item;
}
return null;
}
}
}

public abstract class LookupListWrapperBase
{

public event EventHandler SelectedIndexChanged;

/// <summary>
/// exposed for inheritors to do testing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OnSelectedIndexChanged(object sender, EventArgs e) {
Console.WriteLine("Entering OnSelectedIndexChanged");
if (SelectedIndexChanged != null)
SelectedIndexChanged(sender, e);
}

public abstract ILookupDTO SelectedItem { get; }
public abstract void Add(ILookupDTO lookupDto);
public abstract void Clear();

}
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 26 Oct 2008 13:27:20 -0700, Berryl Hesh <ef******@yahoo.com>
wrote:
>I wouldn't nomally post this here, as it has something to do with the
ListView control usage I think, or maybe with a race condition or some
windoes messaging. I'm just not sure.

A race condition requires more than one thread. Do you have a second
thread?

You've only posted a single method, which by itself isn't nearly enough to
illustrate a specific problem, never mind a race condition. At a minimum,
you need to more completely describe the code involved here, and really
you should post a concise-but-complete code example that reliably
demonstrates the problem.

I can certainly imagine that if you're calling that code from a thread
other than the one that owns the control, you _might_ get the behavior
you're observing. But speculating isn't a very useful way to debug code.

Pete

Oct 26 '08 #3

P: n/a
On Sun, 26 Oct 2008 15:25:48 -0700, Berryl Hesh <ef******@yahoo.comwrote:
[...]
That's where I get to my previous post, as I can't yet prove or disprove
what's going on with the event firing in the debugger after I examine it,
but not otherwise.

Cheers, and thanks for sharing. BH
You may find these articles helpful:

http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/
Oct 26 '08 #4

P: n/a
Got it...

The problem was that the control had no Handle from my code, which turns out
to be as easy as using CreateControl(). The debugger must create a handle to
examine the control properties, which was forcing the SelectedItems property
to work.

That's (3) things I learned as a result of your 'bossy' response, so
thanks!! I still think you just don't like me though :-)
Oct 27 '08 #5

P: n/a
On Sun, 26 Oct 2008 18:52:08 -0700, Berryl Hesh <ef******@yahoo.comwrote:
[...]
That's (3) things I learned as a result of your 'bossy' response, so
thanks!! I still think you just don't like me though :-)
Sorry you thought my response was bossy. I wasn't being bossy at all and
as far as whether I like you or not, I can't imagine how I could possibly
have an opinion one way or the other.

The fact is, you asked a question that couldn't be answered. I tried to
give you enough information so that you could provide a question that
_could_ be answered.

Now, you can get defensive about that attempt to help you, or you can
engage in some introspection and recognize that you apparently have
something to learn about posting effective questions. There's a reason
that more than one person has taken the time to write an lengthy document
about how to post effective questions; ignoring that fact simply means you
won't ever get the kind of help you want.

Your choice. No skin off my nose (or anyone else's), as the only person
for whom there are negative consequences for our failure to answer your
question is you. If you make it impossible to answer your question,
that's your own problem. The only possible reason I could have to even
bring it up is for your benefit. Getting defensive about the issue is
just plain silly.

Pete
Oct 27 '08 #6

P: n/a
Pete

I was kidding with you, buddy. The "Bossy" and "I don't like you" references
are from your own link http://www.yoda.arachsys.com/csharp/incomplete.html
which I enjoyed immensely.

Thanks Again (seriously!)
Berryl
Oct 27 '08 #7

P: n/a
On Sun, 26 Oct 2008 20:08:55 -0700, Berryl Hesh <ef******@yahoo.comwrote:
Pete

I was kidding with you, buddy. The "Bossy" and "I don't like you"
references
are from your own link
http://www.yoda.arachsys.com/csharp/incomplete.html
which I enjoyed immensely.
Ah, okay. The joke went over my head (I didn't write those articles, so I
sometimes forget what language precisely is used in them). Sorry for the
rant.
Thanks Again (seriously!)
You're welcome. Seriously. :)

Pete
Oct 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.