471,337 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

wierd exception

Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so I
can't reproduce where exactly it happens. I can generally say it happens when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh
May 28 '07 #1
10 2682
I take it you are not, yourself, doing anything with unsafe mode or anything
unusual?

How do you close the application? Application.Exit() ? Closing the main
form? Something else?
"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.com...
Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so
I
can't reproduce where exactly it happens. I can generally say it happens
when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&
m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&
m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh

May 28 '07 #2
You are correct.
I have no idea what these methods do.
I close the application using System.Environment.Exit(-1).
--
dshemesh
"Michael A. Covington" wrote:
I take it you are not, yourself, doing anything with unsafe mode or anything
unusual?

How do you close the application? Application.Exit() ? Closing the main
form? Something else?
"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.com...
Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so
I
can't reproduce where exactly it happens. I can generally say it happens
when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&
m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&
m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh


May 28 '07 #3
Try this:
http://www.ondotnet.com/pub/a/dotnet...readabort.html

HTH :)

Basically, ThreadAbortException is thrown when thread is being aborted
to alert user to perform maintenance cleansing. It's benign exception
and you can do this for quick fix:

try
{
.................your code................
}
catch (ThreadAbortException)
{
}

May 28 '07 #4
On May 28, 10:22 am, dshemesh <dshem...@discussions.microsoft.com>
wrote:
Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so I
can't reproduce where exactly it happens. I can generally say it happens when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh
Are you spawning threads in your app?
Sometimes it happens when you close an application and some threads
are still running.

May 28 '07 #5

"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:75**********************************@microsof t.com...
You are correct.
I have no idea what these methods do.
I close the application using System.Environment.Exit(-1).
See also:

http://geekswithblogs.net/mtreadwell...6/06/6123.aspx

May 28 '07 #6

"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:75**********************************@microsof t.com...
You are correct.
I have no idea what these methods do.
I close the application using System.Environment.Exit(-1).
System.Environment.Exit(code) expects you to stop all the other threads
first. In a windowed application. Application.Exit() is preferred. Is
there a good reason a windowed app needs to return an exit code?
May 28 '07 #7
I don't really have to return an exit code, so there is no problem for me to
use Application.Exit(). Will this stop all the running threads for me?

--
dshemesh
"Michael A. Covington" wrote:
>
"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:75**********************************@microsof t.com...
You are correct.
I have no idea what these methods do.
I close the application using System.Environment.Exit(-1).

System.Environment.Exit(code) expects you to stop all the other threads
first. In a windowed application. Application.Exit() is preferred. Is
there a good reason a windowed app needs to return an exit code?
May 29 '07 #8
I do not know of any threads usage in my code. Maybe since I have a few forms
in the application some threads are opened and closed automatically (and then
one or more is not closed properly?)?
--
dshemesh
"Jorge" wrote:
On May 28, 10:22 am, dshemesh <dshem...@discussions.microsoft.com>
wrote:
Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so I
can't reproduce where exactly it happens. I can generally say it happens when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh

Are you spawning threads in your app?
Sometimes it happens when you close an application and some threads
are still running.

May 29 '07 #9
Hi Michael,
I tried using Application.Exit() and encountered the following problems:
1. After calling Application.Exit() the code continues to run. It does not
really terminate the application (I am calling Application.Exit() from the
main method of my application). I see this when in debug mode.
2. I still get sometimes the exception...

thanks,
--
dshemesh
"Michael A. Covington" wrote:
>
"dshemesh" <ds******@discussions.microsoft.comwrote in message
news:75**********************************@microsof t.com...
You are correct.
I have no idea what these methods do.
I close the application using System.Environment.Exit(-1).

System.Environment.Exit(code) expects you to stop all the other threads
first. In a windowed application. Application.Exit() is preferred. Is
there a good reason a windowed app needs to return an exit code?
May 29 '07 #10
When checking the code more thoroughly It looks something like this:

void Main {
int retval = foo();
if (retval == FAILED) {
System.Environment.Exit(-1); }
else {
System.Windows.Forms.Application.Run(new psScheduleTasks()); }
}

void foo {
Thread a;
a = new Thread(new ThreadStart(ShowWaitScreen));
a.Start();
more code...

a.abort();
return retval;
}

The exception is thrown when foo returns FAILED.
I tried using System.Windows.Forms.Application.Exit() instead of
System.Environment.Exit(-1), but the exception is still begin thrown.
--
dshemesh
"Jorge" wrote:
On May 28, 10:22 am, dshemesh <dshem...@discussions.microsoft.com>
wrote:
Hello,
I have a C# project with windows forms.
I sometimes get unprdictable .NET exceptions. I don't always get them, so I
can't reproduce where exactly it happens. I can generally say it happens when
closing the application (maybe in the dispose method?).
Here are 2 examples:

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.CallWindo wProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Messa ge& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Windows.Forms.UnsafeNativeMethods.SetFocus( HandleRef hWnd)
at System.Windows.Forms.ContainerControl.FocusActiveC ontrolInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Any ideas?

thanks,
--
dshemesh

Are you spawning threads in your app?
Sometimes it happens when you close an application and some threads
are still running.

May 29 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sathyaish | last post: by
112 posts views Thread by Tom | last post: by
1 post views Thread by Sao Zagoranski | last post: by
5 posts views Thread by desktop | last post: by
1 post views Thread by Bobby Edward | last post: by
4 posts views Thread by Cirene | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.