TimerTask Executor

05/28/2011 18:16 ImmuneOne#1
Do with it whatever you want. Feel free to ask any question(s).
05/28/2011 20:07 .Kinshi#2
Sexy dude!
05/28/2011 22:11 pro4never#3
Nice work ^^

Doubt very many people will end up using it but it's very cool. We've been experimenting with similar concepts on hellmouth although we've currently switched to what is essentially managed timers. It works fantastically so far.
05/28/2011 23:05 F i n c h i#4
Good job, I really needed it.
05/28/2011 23:18 ImmuneOne#5
Quote:
Originally Posted by alexalx View Post
Good job, I really needed it.
Even though thinking it's a good job. May I ask for what and why you needed this?
05/28/2011 23:45 _Emme_#6
Looking neat bro. For those who wants to keep things cleaner, for the initializing part.

Instead of
Code:
TimerTaskExecutor executor = new TimerTaskExecutor();

TimerTask task = new TimerTask(execute);
task.setWaitTime(2000);
executor.ExecuteTimerTask(task);
You could simply just:

Code:
new TimerTaskExecutor().ExecuteTimerTask(new TimerTask(execute) { sleepTime = 2000 });
+TimerTask.cs:
Code:
public int sleepTime { get { return _waitTime; } set { _waitTime = value; } }

Keep it up bro!
05/29/2011 00:21 ImmuneOne#7
Quote:
Originally Posted by EmmeTheCoder View Post
Looking neat bro. For those who wants to keep things cleaner, for the initializing part.

Instead of
Code:
TimerTaskExecutor executor = new TimerTaskExecutor();

TimerTask task = new TimerTask(execute);
task.setWaitTime(2000);
executor.ExecuteTimerTask(task);
You could simply just:

Code:
new TimerTaskExecutor().ExecuteTimerTask(new TimerTask(execute) { sleepTime = 2000 });
+TimerTask.cs:
Code:
public int sleepTime { get { return _waitTime; } set { _waitTime = value; } }

Keep it up bro!
Wouldn't make a difference you're still creating new instances. Besides, the wait times aren't ment to be changed after being set.. so yeah.
05/29/2011 00:37 _Emme_#8
Quote:
Originally Posted by ImmuneOne View Post
Wouldn't make a difference you're still creating new instances. Besides, the wait times aren't ment to be changed after being set.. so yeah.
Yeah, ofcourse, but what I was aiming for was if you're going to have a set of threads/timers (possibly not for CO, but for other applications as this is not CO related really), it'd be easier to manage and organize the initialization the way I suggested - both works the same just saves a couple of rows.
05/29/2011 00:55 _DreadNought_#9
Looks, In my eyes, Interesting.

I like the idea of TimerTask however much I think
Code:
            TimerTaskExecutor executor = new TimerTaskExecutor();

            TimerTask task = new TimerTask(execute);
            task.setWaitTime(2000);
            executor.ExecuteTimerTask(task);
Is quite a handful.

I notice that the DateTime function is used alot too, Wouldnt it be better to use the TIME function? aka time32 which I believe is a native C++ function.

And would you like to explain why do all of what your doing when
Code:
new Thread(Core).Start();

void Core()
{
if (LastCheck.AddMili <= CurrentTime)
{
LastCheck = CurrentTime;
blabla
}
Seems smaller and easier.

However, I've tested this minorly(<-- not a word o.o) and it does appear to work and do its job with minimal resources.

Nice work, If my threading system doesnt work out its very nice to know I've got something to fall back on. +K
}
05/29/2011 11:15 ImmuneOne#10
Quote:
Originally Posted by EmmeTheCoder View Post
Yeah, ofcourse, but what I was aiming for was if you're going to have a set of threads/timers (possibly not for CO, but for other applications as this is not CO related really), it'd be easier to manage and organize the initialization the way I suggested - both works the same just saves a couple of rows.
Who said it is co related? However, you could easily implement this into a co environment.

Code:
            TimerTask staminaTask = new TimerTask(client, execute);
            staminaTask.setWaitTime(2000);
            executor.ExecuteTimerTask(staminaTask);

        static bool execute(object targObj, DateTime timeofExecution)
        {
            //update stamina perhaps?
            Console.WriteLine("Executed!");
            return true;
        }
05/29/2011 13:17 _Emme_#11
Quote:
Originally Posted by ImmuneOne View Post
Who said it is co related?
It's in the CO section darling :rolleyes:

Anyhow, yes, and that's what makes these kind of codes beautiful, they can be implemented onto any project :)
05/29/2011 14:07 _DreadNought_#12
Quote:
Originally Posted by ImmuneOne View Post
Who said it is co related? However, you could easily implement this into a co environment.

Code:
            TimerTask staminaTask = new TimerTask(client, execute);
            staminaTask.setWaitTime(2000);
            executor.ExecuteTimerTask(staminaTask);

        static bool execute(object targObj, DateTime timeofExecution)
        {
            //update stamina perhaps?
            Console.WriteLine("Executed!");
            return true;
        }
Was meant to ask, Why make "client" an object when a foreach loop is just as easy.
05/29/2011 14:40 ImmuneOne#13
Quote:
Originally Posted by _DreadNought_ View Post
Was meant to ask, Why make "client" an object when a foreach loop is just as easy.
You'd have to compare lastStamina.AddSeconds(2) and DateTime.Now with every single object.
05/29/2011 15:09 _DreadNought_#14
Why not make it generic, not dynamic?
05/30/2011 01:05 ImmuneOne#15
Quote:
Originally Posted by _DreadNought_ View Post
Why not eat chocolate pie, not apple pie?
Because apple pie is actually more delicious than chocolate pie.