Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 15:11

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

Advertisement



Thread Stops working on its own HELP!

Discussion on Thread Stops working on its own HELP! within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Oct 2008
Posts: 342
Received Thanks: 66
Thread Stops working on its own HELP!

Its set so this thread runs every 500ms. Im aware here arent any Try/Catch blocks. They didnt catch anything.

After some jumping, or just waiting the thread stops. I cant figure out where the problem is at... Its not a dead loop, not a dead lock,...

PHP Code:
public static void CharThread()
       {
           
lock (Kernel.AllChars)
           {
               foreach (
KeyValuePair<uintCharacterCharr in Kernel.AllChars)
               {
                   
Character MyChar Charr.Value;

                   if (
MyChar.DoubleEXP)
                   {
                       
DoubleExp.Handle(MyChar);
                   }
                   if (
MyChar.Attacking)
                   {
                       
HandleAttack.Attack(MyChar);
                   }
                   if (
MyChar.CastingPray || MyChar.Praying)
                   {
                       
LuckyTime.Handle(MyChar);
                   }
                   
GeneralHandling.Handle(MyChar);
               }
               
Thread.Sleep(1);
           }
       } 
Edit: This way seems to work... atleast works since now but idk why.. Im just scared itll crash at one point tho

PHP Code:
public static void CharThread()
       {
           
lock (Kernel.AllChars)
           {
               
IDictionaryEnumerator DE Kernel.AllChars.GetEnumerator();
               try
               {
                   while (
DE.MoveNext())
                   {
                       
Character MyChar = (Character)DE.Value;

                       if (
MyChar.DoubleEXP)
                       {
                           
DoubleExp.Handle(MyChar);
                       }
                       if (
MyChar.Attacking)
                       {
                           
HandleAttack.Attack(MyChar);
                       }
                       if (
MyChar.CastingPray || MyChar.Praying)
                       {
                           
LuckyTime.Handle(MyChar);
                       }
                       
GeneralHandling.Handle(MyChar);
                   }
               }
               
finally
               
{
                   
IDisposable disposable DE as IDisposable;

                   if (
disposable != null)
                       
disposable.Dispose();
               }
               
Thread.Sleep(1);
           }
       } 
µ~Xero~µ is offline  
Old 08/31/2010, 00:48   #2


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
You dont loop the void so it does it once and then closes.

Eg:

Code:
        private static bool DoWork = true;

        static void ThreadWorker()
        {
            while (DoWork)
            {
                //Perform Work
            }
        }
Korvacs is offline  
Old 08/31/2010, 00:52   #3
 
elite*gold: 0
Join Date: Oct 2008
Posts: 342
Received Thanks: 66
I´m afraid i dont get it, sorry..
could you try explaining in-depth?

EDIT: Im using that LIKE a timer. A thread with intervall.

PHP Code:
public class ThreadTimer
    
{
        public 
event Execute Execute;
        
Thread T;
        
        
DateTime DT;
        
uint interval;
        
/// <summary>
        /// Starts the Thread on specific Intervall(Miliseconds)
        /// </summary>
        /// <param name="Interval"></param>
        
public void Start(uint Interval)
        {
                
interval Interval;
                
= new Thread(new ThreadStart(Run));
                
T.Start();
        }
        
bool closed false;
        
/// <summary>
        /// Stops The Thread
        /// </summary>
        
public void Close()
        {
            
closed true;
        }
        
/// <summary>
        /// Starts the Thread
        /// </summary>
        
void Run()
        {
            try
            {
                while (
true)
                {

                    if (
DateTime.Now DT.AddMilliseconds(interval))
                    {
                        
DT DateTime.Now;
                        try
                        {
                            
Execute.Invoke();
                        }
                        catch (
Exception e) { GUI.g.WriteToRichBox("Threading SYstem Error! \n\r" e1); Thread.Sleep(1); }
                    }
                    
Thread.Sleep(1);
                }
            }
            catch (
Exception e)
            {
                
Debug.WriteLine("Threading Error: A Thread crashed while executing! LOG: " e.ToString());
                
Thread.Sleep(1);
            }
        }
    } 
µ~Xero~µ is offline  
Old 08/31/2010, 00:53   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Quote:
Originally Posted by Korvacs View Post
You dont loop the void so it does it once and then closes.

Eg:

Code:
        private static bool DoWork = true;

        static void ThreadWorker()
        {
            while (DoWork)
            {
                //Perform Work
            }
        }
Sorry just edited my post.

If you dont tell create some form of loop to perform the work required, then the thread will call the void once (and only once) and then the void will return, and the thread will close itself because it beleives its finshed.

Quote:
Originally Posted by µ~Xero~µ View Post
I´m afraid i dont get it, sorry..
could you try explaining in-depth?

EDIT: Im using that LIKE a timer. A thread with intervall.

PHP Code:
public class ThreadTimer
    
{
        public 
event Execute Execute;
        
Thread T;
        
        
DateTime DT;
        
uint interval;
        
/// <summary>
        /// Starts the Thread on specific Intervall(Miliseconds)
        /// </summary>
        /// <param name="Interval"></param>
        
public void Start(uint Interval)
        {
                
interval Interval;
                
= new Thread(new ThreadStart(Run));
                
T.Start();
        }
        
bool closed false;
        
/// <summary>
        /// Stops The Thread
        /// </summary>
        
public void Close()
        {
            
closed true;
        }
        
/// <summary>
        /// Starts the Thread
        /// </summary>
        
void Run()
        {
            try
            {
                while (
true)
                {

                    if (
DateTime.Now DT.AddMilliseconds(interval))
                    {
                        
DT DateTime.Now;
                        try
                        {
                            
Execute.Invoke();
                        }
                        catch (
Exception e) { GUI.g.WriteToRichBox("Threading SYstem Error! \n\r" e1); Thread.Sleep(1); }
                    }
                    
Thread.Sleep(1);
                }
            }
            catch (
Exception e)
            {
                
Debug.WriteLine("Threading Error: A Thread crashed while executing! LOG: " e.ToString());
                
Thread.Sleep(1);
            }
        }
    } 
If your going to the trouble of trying to write your own sort of timer, why not just use the Timer class which is in the framework, it will do exactly what you want, and it runs on its own thread.
Korvacs is offline  
Old 08/31/2010, 01:06   #5
 
elite*gold: 0
Join Date: Oct 2008
Posts: 342
Received Thanks: 66
My ThreadTimer Class works more efficient than a timer does. Ive discovered a small performance plus.

Also you have stated if i use a "foreach loop" it will only call the void once, which i cant copy.

Eg. Mob Thread: Same as my CharThread(1st code) runs over and over.

My CharThread (1st Code) runs like 20 times too then it stops.
µ~Xero~µ is offline  
Old 08/31/2010, 01:23   #6


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Quote:
Originally Posted by µ~Xero~µ View Post
My mob thread is exactly same as my char thread (1st code). It doesnt stop.

My ThreadTimer Class works more efficient than a timer does. Ive discovered a small performance plus.

Also you have stated if i use a "foreach loop" it will only call the void once, which i cant copy.

Eg. Mob Thread: Same as my CharThread(1st code) runs over and over.

My CharThread (1st Code) runs like 20 times too then it stops.
No, what i said (based on your first post) was that if you start a thread and call a void without a loop in it, it will call once and return, this is true. What you failed to mention was that you had anouther thread starting the second thread over and over.

I dont remember mentioning a foreach loop, i showed you an example, the foreach loop would be called once, and then since the foreach loop isnt infinite it would close at some stage, the void would return and the thread would close.

As for your claim that it improves performance, i find that highly unlikely, your using 1 thread, to cycle and start numerous threads repeatedly, where as the timer is 1 thread, which performs an action every given interval, sort of like this:

This is just an example, i have not bothered to test it, however i beleive this would work perfectly fine.

Code:
        private static bool DoWork = true;

        static void Worker(long Interval)
        {
            TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime;

            while (DoWork)
            {
                if ((begin - Process.GetCurrentProcess().TotalProcessorTime).Ticks >= Interval)
                {
                    //Perform Work
                    begin = Process.GetCurrentProcess().TotalProcessorTime;
                }
            }
        }
All in one thread, work is performed every interval as required, nothing to worry about, not spawning hundreds of threads needlessly.
Korvacs is offline  
Thanks
1 User
Old 08/31/2010, 01:28   #7
 
elite*gold: 0
Join Date: Oct 2008
Posts: 342
Received Thanks: 66
Now everything is clear! Thanks alot for having the needed patience with me

Also idk why but If i use timers, my CPU Usage goes up to 4% where it uses as it is now 1%

Ima try your way tho.

Last thing i dont get:

Why did my 1st code not work and why does the second one?
µ~Xero~µ is offline  
Old 08/31/2010, 01:36   #8


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Not sure, i would need to debug it myself to understand your system fully.

If your worried about using timers that much, write a thread similar to what i just showed you where you check the interval inside a loop and perform your work as and when you need to, also make sure you have a Thread.Sleep(1) in there somewhere otherwise your CPU usage will skyrocket.

And no problem, thanks for listening, makes a change
Korvacs is offline  
Thanks
1 User
Old 08/31/2010, 01:41   #9
 
elite*gold: 0
Join Date: Oct 2008
Posts: 342
Received Thanks: 66
Ill work on some system like you suggested now. thanks a lot for clearing things up!

We can be proud to have you supporting us. even tho u made me get banned =(..<3

can now be closed if you want to.
µ~Xero~µ is offline  
Reply


Similar Threads Similar Threads
[ZSZC]DB-Bot Stops!
06/25/2010 - SRO Private Server - 2 Replies
I've setup all settings and my bot doesnt want to attack mobs(i use level range)
Checking if you i-net stops?
04/17/2009 - Silkroad Online - 10 Replies
Is there any program that can see if your internet breaks down over night? Cause I would love to see/know that program, cause my i-net shouldn't shut down but I think it does. So if there is a program that can detect that, would be nice to share.
AgBot just stops working
03/22/2009 - Silkroad Online - 7 Replies
Hello, I am using agbot about 6 months but i had never had such a problem.The bot was killing mobs and its just stoped. I thought i need to do a teleport but then also didnt happened anything i push start walkscript everything starts except horse casting (in bot console shows that horse is casted but in real its not). And bot just stands and do nothing. Sometimes then its happening in bot console writes: "Error, not moving...Recast movement...". Maybe anybody can help me with that? Thanks.
Cabalrider stops working XX seconds sometimes
08/10/2008 - Cabal Online - 4 Replies
Ola al, Sometimes our cabalrider stops attacking mobs with no reason. It just stands there using pots... thats it. 10 secs later it starts again, sometimes it dusnt... untill it dies and then it walks back to redo the whole process. Anyone has a clue whats wrong ?
Bot stops working after 3 kills
03/11/2008 - Silkroad Online - 1 Replies
Everything loads beautifully, and starts out perfect, but after the third kill it stops finding targets and stops picking up items. I've edited the skills, modified the ip address, and turned up the system priorities on the bot, nuconnector and silkroad in varying combinations. What am I missing? I've been digging through the forums for days now and can't find anything that applys. Any constructive/positive replys are appreciated.



All times are GMT +1. The time now is 15: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.