c#thread的终止后怎么启动
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Text;
namespace Thread.Stop
{
/// <summary>
/// 文件服务
/// </summary>
public class FileService
{
private volatile bool isStop;
private System.Threading.Thread fileThread = null;
public FileService()
{ }
/// <summary>
/// 启动服务
/// </summary>
public void Start()
{
fileThread = new System.Threading.Thread(new System.Threading.ThreadStart(TranslateFile));
fileThread.Start();
}
/// <summary>
/// 中止服务
/// </summary>
public void Stop()
{
isStop = true;
if (fileThread != null && fileThread.ThreadState == System.Threading.ThreadState.Running)
fileThread.Abort();
fileThread = null;
}
private void TranslateFile()
{
while (!isStop)
{
//模拟长时间操作
Console.WriteLine("文件服务输出!");
}
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Thread.Stop
{
/// <summary>
/// 文件服务
/// </summary>
public class FileService
{
private volatile bool isStop;
private System.Threading.Thread fileThread = null;
public FileService()
{ }
/// <summary>
/// 启动服务
/// </summary>
public void Start()
{
fileThread = new System.Threading.Thread(new System.Threading.ThreadStart(TranslateFile));
fileThread.Start();
}
/// <summary>
/// 中止服务
/// </summary>
public void Stop()
{
isStop = true;
if (fileThread != null && fileThread.ThreadState == System.Threading.ThreadState.Running)
fileThread.Abort();
fileThread = null;
}
private void TranslateFile()
{
while (!isStop)
{
//模拟长时间操作
Console.WriteLine("文件服务输出!");
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询