在 System.Threading.ThreadAbortException 中第一次偶然出现的“System.Windows.Forms.dll”类型的异常
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace CPUI.Common
{
/// <summary>
/// 实现等待窗体
/// </summary>
public class WaitFormService
{
/// <summary>
///
/// </summary>
public static void CreateWaitForm()
{
WaitFormService.Instance.CreateForm();
}
public static void CloseWaitForm()
{
WaitFormService.Instance.CloseForm();
}
public static void SetWaitFormCaption(string text)
{
WaitFormService.Instance.SetFormCaption(text);
}
private static WaitFormService _instance;
private static readonly Object syncLock = new Object();
public static WaitFormService Instance
{
get
{
if (WaitFormService._instance == null)
{
lock (syncLock)
{
if (WaitFormService._instance == null)
{
WaitFormService._instance = new WaitFormService();
}
}
}
return WaitFormService._instance;
}
}
private WaitFormService()
{
}
private Thread waitThread;
private WaitForm waitForm;
public void CreateForm()
{
try
{
if (waitThread != null)
{
try
{
waitThread.Abort();
waitThread.Join();
}
catch (Exception)
{
Console.Write("3");
}
}
waitThread = new Thread(new ThreadStart(delegate()
{
waitForm = new WaitForm();
Console.Write("线程阿萨德发生了的快放假啊鹿鼎记flaklllllllllllllllllllllllllllllllllllll" + waitForm.InvokeRequired);
Application.Run(waitForm);
}));
waitThread.Start();
}
catch (Exception ex)
{
Console.Write("asdasdasdasdasda:"+ex.Message);
}
}
public void CloseForm()
{
if (waitThread != null)
{
try
{
waitThread.Abort();
//waitForm.Dispose();
//waitThread.Abort();
//waitThread.Join();
//waitThread.DisableComObjectEagerCleanup();
}
catch (Exception ex)
{
Console.Write(ex.Message);
throw ex;
}
}
}
public void SetFormCaption(string text)
{
if (waitForm != null)
{
try
{
waitForm.SetText(text);
}
catch (Exception)
{
Console.Write("1");
}
}
}
}
}