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~µ
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;
T = 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" + e, 1); 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.
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.
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
[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.