-
Why does my program run with strange order?
Could somebody please suggest me at what situation a progarm could run with the order that is not as it looks like.
eg: When the code should run sequencely, it does not.
In my case, I don't have many threads: I have a GUI and a main. The program will begin to run until it gets the GUI interface and then it stops to wait for me to press one button to continue. A lot of strange problems come out after that. This is one of it.
I am not sure where my problem resides, but it starts to be strange near something like the following (when it prints something. )
public void waitToStart(PrintWriter pW)throws IOException
{
while(!start){}
startRun(pW);
}
public void startRun(PrintWriter pW)throws IOException
{
while(!finished)
{
.
.
.
System.out.println("******");
pW.println("******");
pW.flush();
.
.
.
}
}
Any suggestions please. Thanks very much.
-
If you have no threads then this looks strange indeed. I would have done the following
changes:
The waitToStart method should be invoked by an eventhandler (the buttons
actionPerformed ?) or invoked at end of GUI initiation, loose the while(!start)
{} "thing", set finished=false, and finally create & start a normal priority
thread that perform the while(!finished) -loop. You would probably (?) also
need a button with an eventhandler that sets finished=true if this flag isn't
set (safely) within the while(!finished) -loop.
Last edited by sjalle; 07-26-2005 at 04:24 AM.
eschew obfuscation
-
Thanks a lot sjalle. It is solved.
Only to call the waitToStart method in an eventhandler is enough to me so far.
But why I can not do it the way I did it before?
Thanks.
-
Well, a tight loop like while(!start) {}, when start initially = false,
doesn't allow much other things to happend, like setting start=true....
eschew obfuscation
Similar Threads
-
By James in forum VB Classic
Replies: 5
Last Post: 04-26-2002, 01:42 PM
-
By Paul in forum VB Classic
Replies: 0
Last Post: 10-18-2001, 02:10 AM
-
By Marty in forum VB Classic
Replies: 2
Last Post: 04-19-2001, 12:38 AM
-
By Bruno Baker in forum VB Classic
Replies: 0
Last Post: 08-17-2000, 03:35 PM
-
By Leopoldo Rodriguez in forum VB Classic
Replies: 0
Last Post: 07-11-2000, 06:15 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|