![]() |
getting timer to return booleen variable?
I am currently working on a project with a timer in it. I am having trouble getting this part of my project to work. I need it to pause for a few seconds before it runs the next method. I can't just place the next method in the tick handler because it needs several variables to be passed to it. I could make the next method into its own class but I need it to modify lots of controls on the current form and this would be the long way around. Is there a way I can make a tick handler return a booleen so that once the time elapses I can run my next method? Any other simple solutions?
:
private static void keepTime() |
Re: getting timer to return booleen variable?
Could you not use a global variable, and then in the on tick event set it equal to what every value suits you, then check to see if it is set, if so call you method or whatever it is you wish to do?
Chris |
Re: getting timer to return booleen variable?
Try using the interval property of the Timer class.
|
Re: getting timer to return booleen variable?
the problem I am having is that i need to pass the values for variables form the method that calls the timer into the method I want to run when the time is elapsed. The tick handler wont take any arguments unless I change the arguments in the method handler but then I get an error because it doesn't match the args in the event handler bind. I am not a great programmer and maybe im just missing something super obvious, but I have tried all sorts of things. I cant get the timer to make the other method pause, and I cant pass the variables through if I start a new method.
|
Re: getting timer to return booleen variable?
If you are using a timer just for the sake of waiting then just put the thread to sleep for 4 seconds. IF you require some activity on the main thread whilst waiting then just create a new thread and then sleep that for 4 seconds. IF you require sleeping more than once then have a look at locking and waiting on an object in a loop. Have a look at this book.
|
Re: getting timer to return booleen variable?
Can you post more code? Im thinking your own event/delegate would help here, however I don't have enough of your code to find out for sure.
|
Re: getting timer to return booleen variable?
here is the code...its for a memory game and i need the button to stay disabled and non visible for a few seconds so that the user can see the second pic even if they guessed wrong. I was hoping to figure it out on my own with a bit of help but i am frustrated now and am just posting what i have...I got rid of my timer for now and am messing around with the threading idea. Its kind of new to me though and I am getting all sorts of error messages in the code Ive written...takes me a bit to debug.
:
public void checkMatch(int intCount3, int intCount2, int intCount4, int ingCount5) |
| All times are GMT -5. The time now is 4:21 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC