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.

Strange Behavior

I have a static struct :

public static LocationPaging stLocationPaging = new LocationPaging();

Which is made up from :

public struct LocationPaging

{

public int Page;

public int MaxPage;

}

Which is used to control the paging of some records. BUT , when I call :

Scanning.stLocationPaging.Page = Scanning.stLocationPaging.Page + 1;

The increment doesn't occur, im quite new to C# , but im sure I have done
this in VB.Net with no issues. What am I over looking ?


Jul 27 '06 #1
3 2242
Ignore the above , I was resetting it back to 1 in my code :(
How embarassing !

"Jon Vaughan" <jo**********@hotmail.comwrote in message
news:1S*********************@fe12.news.easynews.co m...
>I have a static struct :

public static LocationPaging stLocationPaging = new LocationPaging();

Which is made up from :

public struct LocationPaging

{

public int Page;

public int MaxPage;

}

Which is used to control the paging of some records. BUT , when I call :

Scanning.stLocationPaging.Page = Scanning.stLocationPaging.Page + 1;

The increment doesn't occur, im quite new to C# , but im sure I have done
this in VB.Net with no issues. What am I over looking ?


Jul 27 '06 #2
Jon Vaughan wrote:
I have a static struct :

public static LocationPaging stLocationPaging = new LocationPaging();

Which is made up from :

public struct LocationPaging
{
public int Page;
public int MaxPage;
}
Which is used to control the paging of some records. BUT , when I call :

Scanning.stLocationPaging.Page = Scanning.stLocationPaging.Page + 1;
The increment doesn't occur, im quite new to C# , but im sure I have done
this in VB.Net with no issues. What am I over looking ?
Could you post a short but complete example which demonstrates the
problem? Here's a short but complete example which shows it working:

using System;

public struct LocationPaging
{
public int Page;
public int MaxPage;
}

class Test
{
static LocationPaging Foo;

static void Main()
{
Test.Foo.Page = Test.Foo.Page+1;
Console.WriteLine (Test.Foo.Page);
Test.Foo.Page = Test.Foo.Page+1;
Console.WriteLine (Test.Foo.Page);
}
}

Jon

Jul 27 '06 #3
Well, as presented it seems to just about work for me - i.e. the value
increments, but I suspect you are hitting one of the following:

1: value-type handling: if the struct is accessed e.g. through a
property, then the value will be cloned, with you updating the separate
copy
2: volatility: another thread looking at this field directly in a tight
look may not notice the change i.e. the value might be in a register

My first question would be: why is this a struct? It feels like it
should be a class, since you seem to want to share it between callers
(which structs are not geared up to do).

Also - (advisory only) - a: accessing fields directly (rather than
through properties) isn't all that recommended; b: since it is static
you may need to make this thread safe (synchronised access) if you are
ever going to do anything complex with threading, otherwise various
gotchas apply. Sounds like this may not be an issue.

But try making it a class; I suspect this will fix everything.

Marc

Jul 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcus | last post by:
Hello, I recently converted all my existing MyISAM tables to InnoDB tables through phpmyadmin. I noticed some strange behavior whenever I would refresh the screen, as phpmyadmin would report...
36
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested...
0
by: thulsey | last post by:
Hi all, I've got some strange behavior happening in Firefox and Safari (Khtml and Gecko) that displays *almost* fine in IE6.0 (still trying to get pixels to line up, anal anal anal...) To...
1
by: Alexander Inochkin | last post by:
Hi! I found same strange behavior of ASP.NET. It is possible this is the bug. Follow the steps:
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
3
by: sara | last post by:
Very strange behavior, but I suspect some is A2K and some might be for me to correct. Just trying to see if anyone can help and advise. We have a database that's been running for a few years...
1
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and...
19
by: david | last post by:
I took old code and decided to modify it a bit, and I just noticed that it does not compile at all and before server one of severs (main) crashed in the system it was working fine (I am really sure...
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code -----------------------------------...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.