|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System;
namespace Timer
{
class MainClass
{
public static void Main(string[] args)
{
//Schreibe eine Informationszeile
Console.WriteLine("Program with Thread and Timer Ticks");
//Erstelle einen Thread welcher ThreadProc startet
System.Threading.Thread bgthrd =
new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
//Starten des Threads
bgthrd.Start();
//Warten auf weitere Eingaben
Console.ReadLine();
}
//Methode welche als extra Thread aufgerufen wird
private static void ThreadProc()
{
//Erstellen eines Timers
System.Timers.Timer t = new System.Timers.Timer(1000);
//Weist eine Methode zu, welche ausgeführt wird wenn der Timer tickt
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Tick);
//Starten des Timers
t.Start();
}
//Methode welche bei Tick aufgerufen wird
private static void Timer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
//Schreiben von "." in der Konsole
Console.Write(".");
}
}
}
|
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System;
namespace Timer
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Program with Thread and Timer Ticks");
System.Threading.Thread bgthrd =
new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
bgthrd.Start();
Console.ReadLine();
}
private static void ThreadProc()
{
System.Timers.Timer t = new System.Timers.Timer(1000);
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Tick);
t.Start();
}
private static void Timer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
Console.Write(".");
}
}
}
|
Burning Board, entwickelt von WoltLab GmbH.
UbuntuFreunde von Easyy-S und basslord seit 06.12.06
Ubuntufreunde.de runs on ubuntu 10.04





