0
我得到这种类型的错误在下面的功能:我也有ThreadException处理,但仍然得到这样的错误:线程已被中止在委托
private void tmrOneSec_Tick(object sender, EventArgs e)
{
tsSpendTime = tsSpendTime.Add(new TimeSpan(0, 0, 1));
tsRemTime = tsTotalTime.Subtract(tsSpendTime);
if (tsRemTime.Ticks > 0)
clsCommonFunc.MultiThreadSetText(txtTimeRem, clsCommonFunc.GetFormattedTime(tsRemTime));
}
public static void MultiThreadSetText(TextBox TxtBox, string Text)
{
if (TxtBox.InvokeRequired)
{
TxtBox.Invoke((MethodInvoker)delegate
{
MultiThreadSetText(TxtBox, Text);
});
}
else
{
TxtBox.Text = Text;
TxtBox.Refresh();
}
}
和错误是这样的:
Source :: mscorlib
Error :: 6/5/2012 8:51:28 AM
Error Description : Thread was being aborted.
Stack Trace: at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at SE5.clsCommonFunc.MultiThreadSetText(TextBox TxtBox, String Text)
我无法识别确切的问题。
你得到的异常等待来自调用调用返回。尝试将TxtBox.Invoke(...)更改为TxtBox.BeginInvoke(...)。它有帮助吗? –
它的工作很好.. –
我会把它变成一个答案,然后如果你不介意,所以你可以标记问题为答案。 –