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

which method is called first ?

P: n/a
Hi all, I have a question and any suggestions for solutions would be
greatly appreciated.
In my program, I first defined a variable called 'incidence' which has
to be updated at every time step,

public static int incidence = 0;

Then I have a method which is called 'step()' and inside 'incidence' is
updated.

public void step() {
updateIncidence();
}
......

I have another method called 'stepReport()' which writes the
'incidence' into a file.

public void stepReport() {
System.out.printf(" %d infected ( inside stepReport).\n", incidence
);
s += String.format(" %d", incidence );
}
......

I am interested in keeping the variable 'incidence' initialized and
updated at every tick count and thought it worked well. Because If I
see the output from the 'updateIndence(); method', then the output is
congruent with all the other outputs.

But the problem happens when I tried to write the variable 'incidence'
into a file. It is not updated every tick count. the incidence value
inside the method, 'stepReport()' doesn't match
that inside the 'partnerInfection( nodeList );'

So I incorporated a print method inside the 'stepReport()' and the
result is

0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
2 infected.(inside updateIncidence)
2 infected ( inside stepReport).
2 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
1 infected.(inside updateIncidence)
1 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).

So it seems that sometimes, 'stepReport()' method is executed first and
then 'updateIncidence()' is executed. But other times, the opposite.
If it would work, those two methods have to be in same order over
time.

Is there any way to control the order in which the methods are excuted
?

Any suggestions would be appreciated.

Thank you.

Apr 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
thickface <ki*******@gmail.com> wrote:
Hi all, I have a question and any suggestions for solutions would be
greatly appreciated.
In my program, I first defined a variable called 'incidence' which has
to be updated at every time step,
<snip>
Is there any way to control the order in which the methods are excuted
?


Unfortunately, you haven't really shown enough code to see what's going
on. The order in which methods are executed is deterministic (in all
cases I can think of at the moment), and can be controlled fairly
closely.

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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.