473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

race condition?

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
7 2292
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: GIMME | last post by:
One of my coworkers insists that one should never use static methods because race conditions exist. Thinking along the lines that all variable assignments are assignments to static variables. ...
3
by: Juergen Stein | last post by:
Hi Group, I couldn't find an answer on this with Google, so let me test you :) I've a fairly complex WebApp, and I put most of the JS code in independent external .js files. One of these...
2
by: fran | last post by:
Server: IBM XSERIES 225 (Intel Xeon CPU 2.40GHz 1GB RAM) Operating System: Linux RedHat ES 2.1 kernel 2.4.9 Languaje: C++ Compiler: gcc 2.96 Libs: pthread We are in need of your help in...
0
by: Richard | last post by:
Hi, I'm suffering a socket race condition - I think. The code works fine at full speed on a single CPU machine. However when I run full speed on a 2 Zeon machine the socket drops data on an...
5
by: anonymous | last post by:
I'm writing a program that deals extensively with the printer. For the most part my application runs fine, but occasionally I run into some Exceptions. The most common exceptions I run into are...
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
3
by: Ryan Liu | last post by:
Hi, What does ArrayList.Synchronized really do for an ArrayList? Is that equal to add lock(this) for all its public methods and properties? Not just for Add()/Insert()/Remvoe()/Count, but also...
3
by: chris johnson | last post by:
Hello there. I have a script (say, page.js) called from a script tag as such: <script src="page.js"></script> Within page.js, I have something like the following: ...
2
by: antonyliu2002 | last post by:
I do not quite understand the race condition. As I posted a couple of days ago, I create a PDF on the fly in my web application at regular intervals. Users will be able to download the PDF...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.