473,326 Members | 2,081 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,326 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 2238
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.