Register for your free account! | Forgot your password?

You last visited: Today at 13:40

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



TimerTask Executor

Discussion on TimerTask Executor within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old   #1
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
Post TimerTask Executor

Do with it whatever you want. Feel free to ask any question(s).
Attached Files
File Type: rar Threading Experiment.rar (33.6 KB, 105 views)
ImmuneOne is offline  
Thanks
8 Users
Old 05/28/2011, 20:07   #2
 
.Kinshi's Avatar
 
elite*gold: 0
Join Date: Dec 2010
Posts: 341
Received Thanks: 255
Sexy dude!
.Kinshi is offline  
Thanks
1 User
Old 05/28/2011, 22:11   #3
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
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.
pro4never is offline  
Thanks
1 User
Old 05/28/2011, 23:05   #4
 
F i n c h i's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 785
Received Thanks: 421
Good job, I really needed it.
F i n c h i is offline  
Thanks
1 User
Old 05/28/2011, 23:18   #5
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
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?
ImmuneOne is offline  
Thanks
1 User
Old 05/28/2011, 23:45   #6
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,161
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!
_Emme_ is offline  
Thanks
1 User
Old 05/29/2011, 00:21   #7
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
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.
ImmuneOne is offline  
Old 05/29/2011, 00:37   #8
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,161
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.
_Emme_ is offline  
Old 05/29/2011, 00:55   #9
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
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
}
_DreadNought_ is offline  
Old 05/29/2011, 11:15   #10
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
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;
        }
ImmuneOne is offline  
Old 05/29/2011, 13:17   #11
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,161
Quote:
Originally Posted by ImmuneOne View Post
Who said it is co related?
It's in the CO section darling

Anyhow, yes, and that's what makes these kind of codes beautiful, they can be implemented onto any project
_Emme_ is offline  
Thanks
1 User
Old 05/29/2011, 14:07   #12
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
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.
_DreadNought_ is offline  
Old 05/29/2011, 14:40   #13
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
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.
ImmuneOne is offline  
Old 05/29/2011, 15:09   #14
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,223
Received Thanks: 867
Why not make it generic, not dynamic?
_DreadNought_ is offline  
Old 05/30/2011, 01:05   #15
 
ImmuneOne's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 754
Received Thanks: 544
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.
ImmuneOne is offline  
Thanks
2 Users
Reply




All times are GMT +2. The time now is 13:40.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.