Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases
You last visited: Today at 17:11

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

Advertisement



[C# 2010] PauseTimer Class

Discussion on [C# 2010] PauseTimer Class within the Coding Releases forum part of the Coders Den category.

Reply
 
Old   #1
 
King Sora's Avatar
 
elite*gold: 6394
Join Date: Nov 2008
Posts: 1,225
Received Thanks: 4,765
[C# 2010] PauseTimer Class

Heyho!
Mich hat es sehr genervt, dass es beim DispatcherTimer keine Methode zum pausieren gab. Also habe ich beschlossen eine Erweiterung in Form von einer neuen Klasse zu schreiben!
Da der "PauseTimer" von der DispatcherTimer Klasse erbt, verhält er sich genau wie ein DispatcherTimer. Bis auf die "Pause" Methode und einem neuen Attribut gibt es nichts wirklich neues was für euch von Bedeutung wäre!
Zur Pause Methode:
Es gibt einen Parameter der übergeben wird. Dieser ist vom Typ PauseStatus (Dieses Enum ist auch neu!)
und gibt an ob die Pause beginnt oder endet. Falls die Pause aufgrund von verschiedenen Gründen nicht beginnen oder
enden kann (Timer läuft garned oder ist schon gestoppt), gibt es Abfragen die Fehler verhindern.

Zum IsPaused Attribut:
Dieses Attribut ist ein Boolean und gibt an, ob der Timer Pausiert ist oder nicht.

Zur Klasse:
PHP Code:
using System;
using System.Windows.Threading;
using System.Diagnostics;

/*
Geschrieben am 19.05.2013.
Geschrieben von King Sora.
*/

public enum PauseStatus BeginEnd }

class 
PauseTimer DispatcherTimer 
{
    private 
Stopwatch _observeTick;
    private 
TimeSpan _oldInterval;
    private 
bool _pausePossible;
    private 
bool _timerIsPaused;

    public 
PauseTimer() : base()
    {
        
this._pausePossible false;
        
this._observeTick = new Stopwatch();
        
this._oldInterval = new TimeSpan(00000);
        
this.Tick += new EventHandler(tick);
    }

    public 
PauseTimer(DispatcherPriority priority
        : 
base(priority)
    {
        
this._pausePossible false;
        
this._observeTick = new Stopwatch();
        
this._oldInterval = new TimeSpan(00000);
        
this.Tick += new EventHandler(tick);
    }

    public 
PauseTimer(DispatcherPriority priorityDispatcher dispatcher
        : 
base(prioritydispatcher)
    {
        
this._pausePossible false;
        
this._observeTick = new Stopwatch();
        
this._oldInterval = new TimeSpan(00000);
        
this.Tick += new EventHandler(tick);
    }

    public 
PauseTimer(TimeSpan intervalDispatcherPriority priorityEventHandler callbackDispatcher dispatcher
        : 
base(intervalprioritycallbackdispatcher)
    {
        
this._pausePossible false;
        
this._observeTick = new Stopwatch();
        
this._oldInterval = new TimeSpan(00000);
        
this.Tick += new EventHandler(tick);
    }

    public 
bool IsPaused
    
{
        
get { return _timerIsPaused; }
        
set { }
    }

    public new 
void Start()
    {
        
base.Start();
        
this._observeTick.Start();
        
this._pausePossible true;
    }

    public new 
void Stop()
    {
        
base.Stop();
        
_observeTick.Stop();
        
this._pausePossible false;
    }

    public 
void Pause(PauseStatus pauseStatus)
    {
        if (
pauseStatus == PauseStatus.Begin && this.IsEnabled && this._observeTick.IsRunning && this._pausePossible == true)
        {
            
this._timerIsPaused true;
            
this._oldInterval this.Interval;
            
this.Interval = new TimeSpan(0000, ((int)this._oldInterval.TotalMilliseconds - (int)_observeTick.ElapsedMilliseconds));
            
this.Stop();
            
this._observeTick.Stop();
        }
        else if (
pauseStatus == PauseStatus.End && this.IsEnabled == false && this._observeTick.IsRunning == false && this._timerIsPaused)
        {
            
this._timerIsPaused false;
            
this.Start();
            
this._observeTick.Start();
            
this.Tick += new EventHandler(tickAfterPause);
        }
    }

    private 
void tickAfterPause(object senderEventArgs e)
    {
        
this.Interval this._oldInterval;
        
this.Start();
        
this.Tick -= new EventHandler(tickAfterPause);
    }

    private 
void tick(object senderEventArgs e)
    {
        
this._observeTick.Restart();
    }

Im Anhang habt ihr nochmal diese Klasse mit Kommentaren!

Programm zum Veranschaulichen:
Ich habe euch noch ein Programm angehängt, das diese Klasse gleich testet.
Screen:


Bevor ichs vergesse, bitte gebt mir Feedback oder Kritik zu der Klasse (ist gern gesehen )
und meldet Bugs oder Fehler.
Ich behebe sie gerne und update diesen Thread!

Hoffentlich hilft euch die Klasse etwas!
Attached Files
File Type: zip PauseTimer Test Programm.zip (72.4 KB, 2 views)
File Type: zip PauseTimer Klasse.zip (1.1 KB, 2 views)
King Sora is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
[Release] Class Change Potions
08/11/2012 - EO PServer Guides & Releases - 2 Replies
Now I know most servers have the issue that when they change classes, players abuse bugs and skills. The Modified Class Change Potions From ClassicAcme, It Deletes Skills Not Related to the chosen class. Mage Can Only Use Mage Skills, Warriors Can Only Use Warrior Skills, And Paladins can only use Paladin Skills. Screen Shots To Be Posted Later. update cq_user set soul_value_lev = 1 where profession = 30 and cq_user.level >= 1 and cq_user.level < 50; update cq_user set...
[funny-release] change CLASS npc by addition to pirate class xDDD
01/12/2012 - CO2 PServer Guides & Releases - 30 Replies
all of us wating for pirate decided to code some sort of npc which change ur job in additon to pirate that some sort of fun no more in ur npc.cs or what ever its name add that #region (CharChanger By Eslam) case 17494: { switch (npcRequest.OptionID) { case 0: { dialog.Text("Would u like to change your job?"); dialog.Option("Yes Please", 1); dialog.Option("No.", 255); dialog.Send(); break; }
[Release] Class Potion
03/17/2009 - EO PServer Guides & Releases - 13 Replies
hi guyz , after some ppl started to ask for class potion i thought i should release it All Credits to haciveli AKA Ace



All times are GMT +1. The time now is 17:11.


Powered by vBulletin®
Copyright ©2000 - 2025, 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 ©2025 elitepvpers All Rights Reserved.