修改线程UI错误

This commit is contained in:
gongxh
2022-01-19 13:27:34 +08:00
parent e1731268c0
commit f802acfd18
2 changed files with 340 additions and 324 deletions

View File

@@ -130,35 +130,34 @@ namespace NX_LogUtility
private static void RunLogTask()
{
bool createNew;
string threadName = "LogQueue";
using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew))
//bool createNew;
//string threadName = "LogQueue";
//using (System.Threading.Mutex mtx = new System.Threading.Mutex(true, threadName, out createNew))
//{
// if (createNew)
// {
Task.Factory.StartNew(() =>
{
if (createNew)
//从队列中取元素。
while (!QueueBlock<QueueMessage>.IsComleted())
{
Task.Factory.StartNew(() =>
try
{
//从队列中取元素。
while (!QueueBlock<QueueMessage>.IsComleted())
{
try
{
var m = QueueBlock<QueueMessage>.Take();
SaveLog(m.Content, m.LogType);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
});
var m = QueueBlock<QueueMessage>.Take();
SaveLog(m.Content, m.LogType);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
else
{
Console.WriteLine("日志线程已经运行");
}
}
});
// }
// else
// {
// Console.WriteLine("日志线程已经运行");
// }
//}
}
/// <summary>
@@ -167,7 +166,7 @@ namespace NX_LogUtility
/// <typeparam name="T"></typeparam>
public class QueueBlock<T> where T : class
{
private static BlockingCollection<T> Colls;
private static BlockingCollection<T> Colls = new BlockingCollection<T>();
public QueueBlock()
{