49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.Threading;
|
|
|
|
namespace hello
|
|
{
|
|
public class CarService
|
|
{
|
|
// private readonly string host = ConfigurationManager.AppSettings["Host"];
|
|
// private readonly string port = ConfigurationManager.AppSettings["Port"];
|
|
|
|
private Thread instance;
|
|
|
|
public void Start()
|
|
{
|
|
try{
|
|
isalive=true;
|
|
instance=new Thread(new ThreadStart(CarImpel));
|
|
instance.Start();
|
|
}catch(Exception ex){
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
public void Stop()
|
|
{
|
|
try
|
|
{
|
|
if(instance!=null)
|
|
{
|
|
isalive=false;
|
|
instance.Join(500);
|
|
}
|
|
}finally{
|
|
instance=null;
|
|
}
|
|
}
|
|
|
|
static bool isalive=false;
|
|
|
|
static void CarImpel()
|
|
{
|
|
while(isalive)
|
|
{
|
|
Console.WriteLine(DateTime.Now.ToString());
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
} |