?? uploadlogthread.cs
字號:
using System;
using System.IO;
using System.Threading;
using MonitorSystem.BasicClass;
using MonitorSystem.FtpClient;
namespace MonitorSystem.MonitorInterface
{
/// <summary>
/// 定時從UploadLogQueue中取Log文件,上傳至監控中心指定的目錄下
/// </summary>
public class UploadLogThread
{
private Thread m_Thread;
private bool m_Pause;
private bool m_Exit;
private UploadLogQueue m_UploadLogQueue;
private ConfigFile m_CfgFile;
private SystemLog m_SysLog;
private FTPClass m_ftpClient;
private string m_strUploadFile;
public UploadLogThread()
{
m_SysLog = new SystemLog();
m_Pause = false;
m_Exit = false;
}
public void Init(ref UploadLogQueue iUploadLogQueue,ConfigFile iCfgFile)
{
this.m_UploadLogQueue = iUploadLogQueue;
this.m_CfgFile = iCfgFile;
}
public void Run()
{
while(true)
{
while(m_Pause)
{
try
{
Thread.Sleep(1000);
}
catch(Exception)
{
}
continue;
}
if(m_Exit)
{
break;
}
if (m_UploadLogQueue.Count<=0)
{
try
{
Thread.Sleep(1000);
continue;
}
catch(Exception ex)
{
string msg = ex.Message;
m_SysLog.WriteToSysLog(1,msg);
}
}
else
{
//取一個待上傳文件
try
{
this.m_strUploadFile = (string)m_UploadLogQueue.Dequeue();
}
catch
{
continue;
}
//上傳MONITOR_LOG文件
try
{
m_ftpClient = new MonitorSystem.FtpClient.FTPClass();
m_ftpClient.setRemoteHost(m_CfgFile.CenterIP);
m_ftpClient.setRemotePort(m_CfgFile.CenterPort);
m_ftpClient.setRemoteUser(m_CfgFile.CenterFtpUserName);
m_ftpClient.setRemotePass(m_CfgFile.CenterFtpPsw);
m_ftpClient.setRemotePath(m_CfgFile.CenterLog_Path);
m_ftpClient.login();
m_ftpClient.upload(m_strUploadFile);
File.Delete(m_strUploadFile);
m_ftpClient.close();
}
catch(Exception ex)
{
string msg = String.Format("上傳Monitor_Log文件失敗:{0}",ex.Message);
m_SysLog.WriteToSysLog(0, msg);
}
}
if(m_Exit)
{
break;
}
try
{
//規則鏈表遍歷完畢,線程休眠一分鐘
Thread.Sleep(100);
}
catch(Exception)
{
}
}
}
public void Startup()
{
m_Thread = new Thread(new ThreadStart(this.Run));
// Start the thread
m_Pause = false;
m_Exit = false;
m_Thread.Start();
}
public void Join()
{
if(m_Thread != null)
{
m_Thread.Interrupt();
m_Thread.Join();
}
else
{
return;
}
}
public bool IsAlive()
{
if(m_Thread != null)
{
return m_Thread.IsAlive;
}
else
{
return false;
}
}
public void Suspend()
{
if(m_Pause == false)
m_Pause = true;
}
public void Resume()
{
if(m_Pause == true)
m_Pause = false;
}
public void SetExit()
{
if(m_Exit == false)
m_Exit = true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -