在 System.Threading.ThreadAbortException 中第一次偶然出现的“System.Windows.Forms.dll”类型的异常

cs258dn 2011-12-05 03:14:54
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");
}
}
}

}
}
...全文
378 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangyaomu 2014-05-17
  • 打赏
  • 举报
回复
我也遇到这个问题 win8 不定期报错 求解
cs258dn 2011-12-06
  • 打赏
  • 举报
回复
我调试下。。在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;
}
}
}

抛出异常
zzf2004 2011-12-06
  • 打赏
  • 举报
回复
只是系统给你的一个通知,告诉你当前线程被异常中止了。
waitThread.Abort();
查看MSDN的解释
Abort在调用此方法的线程上引发 ThreadAbortException,以开始终止此线程的过程。调用此方法通常会终止线程。
zzf2004 2011-12-05
  • 打赏
  • 举报
回复
没什么问题吧?
cs258dn 2011-12-05
  • 打赏
  • 举报
回复
跪求 各位高手 帮帮忙吧

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧