Hi,
I am starting a new thread from the main UI thread. If users clicks cancel
button, the thread is aborted:
workerThread.Ab ort();
ThreadAbort Exception is handeled in the worker thread:
catch (System.Threadi ng.ThreadAbortE xception ex)
{
//thread aborted send this message to the client
OnProcessAbort( new WorkerProcessBa lanceEventArgs( ex.Message, 0, 0, false));
}
Everything seems to work. But I am noticing in SQL Profiler that it doesn't
logout active connection as it usually does if I let this thread just run
through. Keep in mind that conection object is not visiable to worker thead.
Worker thread creates another object written by other group of developers
that does all db related work. At this time I can not modify db related
class, because they're working on the new release, so my changes will be
lost.
Is there a way to close all open connections within appDomain when worker
thread is aborted? Thank you. 6 10744
I dont know of your specific case but I am certain you dont want to call
Thread.Abort. It has side effects because thread does not get a chance to
clean up. Instead of calling Abort, can you periodically look and see if an
event has been signalled and then exit the thread gracefully at that point?
--
Ajay Kalra [MVP - VC++] aj*******@yahoo .com
"LP" <lp@a.com> wrote in message
news:us******** ******@TK2MSFTN GP12.phx.gbl... Hi,
I am starting a new thread from the main UI thread. If users clicks cancel button, the thread is aborted:
workerThread.Ab ort();
ThreadAbort Exception is handeled in the worker thread:
catch (System.Threadi ng.ThreadAbortE xception ex)
{
//thread aborted send this message to the client
OnProcessAbort( new WorkerProcessBa lanceEventArgs( ex.Message, 0, 0,
false)); }
Everything seems to work. But I am noticing in SQL Profiler that it
doesn't logout active connection as it usually does if I let this thread just run through. Keep in mind that conection object is not visiable to worker
thead. Worker thread creates another object written by other group of developers that does all db related work. At this time I can not modify db related class, because they're working on the new release, so my changes will be lost.
Is there a way to close all open connections within appDomain when worker thread is aborted? Thank you.
LP <lp@a.com> wrote: I am starting a new thread from the main UI thread. If users clicks cancel button, the thread is aborted:
workerThread.Ab ort();
As Ajay says, that's not a terribly good idea - see http://ww.pobox.com/~skeet/csharp/threads/abort.shtml
ThreadAbort Exception is handeled in the worker thread:
catch (System.Threadi ng.ThreadAbortE xception ex)
{
//thread aborted send this message to the client
OnProcessAbort( new WorkerProcessBa lanceEventArgs( ex.Message, 0, 0, false));
}
Everything seems to work. But I am noticing in SQL Profiler that it doesn't logout active connection as it usually does if I let this thread just run through. Keep in mind that conection object is not visiable to worker thead. Worker thread creates another object written by other group of developers that does all db related work. At this time I can not modify db related class, because they're working on the new release, so my changes will be lost.
It sounds like you don't have an appropriate finally block doing the
clean-up. Note that even though you caught the exception, it will still
be propagated after OnProcessAbort has completed.
Is there a way to close all open connections within appDomain when worker thread is aborted? Thank you.
Not as such - instead, you need to write your code with appropriate
finally blocks to clean things up.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> Not as such - instead, you need to write your code with appropriate finally blocks to clean things up.
Jon,
The problem is that I don't have access to the reference of connection
object that lives inside another class. I am using a data access assembly
developed by another group. Even though I do have access to the source code,
I can't modify. They do use -- using(sqlConn){//code here} , so
theoretically the connection should be disposed if any Exception are
thrown. But apparently it does not get disposed.
I am going to look into singanling the thread when cancel is attempted. And
let it finish running db assembly - whatever it's doing there, and then exit
the thread. So when cancel button is clicked it wont run the next database
related work step in the process, rather then brutally aborting the current
one without giving it a chance to clean up.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... LP <lp@a.com> wrote: I am starting a new thread from the main UI thread. If users clicks
cancel button, the thread is aborted:
workerThread.Ab ort();
As Ajay says, that's not a terribly good idea - see http://ww.pobox.com/~skeet/csharp/threads/abort.shtml
ThreadAbort Exception is handeled in the worker thread:
catch (System.Threadi ng.ThreadAbortE xception ex)
{
//thread aborted send this message to the client
OnProcessAbort( new WorkerProcessBa lanceEventArgs( ex.Message, 0, 0,
false)); }
Everything seems to work. But I am noticing in SQL Profiler that it
doesn't logout active connection as it usually does if I let this thread just
run through. Keep in mind that conection object is not visiable to worker
thead. Worker thread creates another object written by other group of
developers that does all db related work. At this time I can not modify db related class, because they're working on the new release, so my changes will be lost.
It sounds like you don't have an appropriate finally block doing the clean-up. Note that even though you caught the exception, it will still be propagated after OnProcessAbort has completed.
Is there a way to close all open connections within appDomain when
worker thread is aborted? Thank you.
Not as such - instead, you need to write your code with appropriate finally blocks to clean things up.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
LP <lp@a.com> wrote: Not as such - instead, you need to write your code with appropriate finally blocks to clean things up. The problem is that I don't have access to the reference of connection object that lives inside another class. I am using a data access assembly developed by another group. Even though I do have access to the source code, I can't modify. They do use -- using(sqlConn){//code here} , so theoretically the connection should be disposed if any Exception are thrown. But apparently it does not get disposed.
How sure are you that it's not being disposed? Bear in mind that the
physical connection wouldn't be closed - it would just return it to the
pool.
I am going to look into singanling the thread when cancel is attempted. And let it finish running db assembly - whatever it's doing there, and then exit the thread. So when cancel button is clicked it wont run the next database related work step in the process, rather then brutally aborting the current one without giving it a chance to clean up.
Right - that's a much better way of operating.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> How sure are you that it's not being disposed? Bear in mind that the physical connection wouldn't be closed - it would just return it to the pool.
Well, I am running a SQL Profiler trace; usually when thread finishes its
work, I can see ".NET client logout" message in a profiler. However when
thread is aborted I don't see that , also sp_who shows that .NET client is
still actively connected.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com... LP <lp@a.com> wrote: Not as such - instead, you need to write your code with appropriate finally blocks to clean things up.
The problem is that I don't have access to the reference of connection object that lives inside another class. I am using a data access
assembly developed by another group. Even though I do have access to the source
code, I can't modify. They do use -- using(sqlConn){//code here} , so theoretically the connection should be disposed if any Exception are thrown. But apparently it does not get disposed.
How sure are you that it's not being disposed? Bear in mind that the physical connection wouldn't be closed - it would just return it to the pool.
I am going to look into singanling the thread when cancel is attempted.
And let it finish running db assembly - whatever it's doing there, and then
exit the thread. So when cancel button is clicked it wont run the next
database related work step in the process, rather then brutally aborting the
current one without giving it a chance to clean up.
Right - that's a much better way of operating.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
LP <lp@a.com> wrote: How sure are you that it's not being disposed? Bear in mind that the physical connection wouldn't be closed - it would just return it to the pool.
Well, I am running a SQL Profiler trace; usually when thread finishes its work, I can see ".NET client logout" message in a profiler. However when thread is aborted I don't see that , also sp_who shows that .NET client is still actively connected.
Well, the .NET client should still be connected - I don't know why it
would normally log out, unless your data layer is deliberately closing
the physical connection (which means you're not using connection
pooling).
I know you're not in control of the real data layer, but I'd try to
knock up a test program to see what makes it log out and when.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bill |
last post by:
Say I have a childThread currently is running a finally block to
cleanup external resources. At the same time the main thread calls
childThread.Abort(). The question is: when the ThreadAbortException
is thrown, does the childThread finish the remaining code in the
finally block?
|
by: Doug Thews |
last post by:
I ran into an interesting re-pain delay after calling the Abort() method on
a thread, but it only happens the very first time I call it. Every time
afterward, there is no delay.
I've got a delegate inside the UI that I call to update the progress meter.
I use the Suspend() and Abort() methods based on button events.
I can watch the progress meter increase just fine when the thread is
running. When I select Start, I enable the Cancel...
|
by: Urs Vogel |
last post by:
Hi
I wrote an application server (a remoting sinlgeton), where processes must
be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and
only after a Thread.Abort(), this component becomes instabile, throwing a
Windows like error (access violation on 0x00000002), not an framework
exception. The component and all of its subcomponents are 100% managed code.
What could go wrong with Thread.Abort()?
Thanks for any hints.
|
by: Joe HM |
last post by:
Hello -
I have a function that calls Thread.Abort() to stop a thread in a
_Closed() Method of a GUI. The thread contains a blocking call on a
TCP socket and that is the easiest way to stop that.
This thread is also outputting strings in a RichTextBox and in some
rare instances I get a System.NullReferenceException when I exit the
GUI. It seems like the _Closed() Method calls Thread.Abort() and then
continues closing down/disposing...
|
by: andrew |
last post by:
Hi,
I have the following issue with the Thread.Abort():
The main thread creates a worker thread which waits on a process
termination.
void ThreadProc()
{
Process proc = proc.Start("notepad.exe");
| |
by: mehdi |
last post by:
Hi folks,
You know, the Thread class has got a method named Abort which
according to the msdn:
"Raises a ThreadAbortException in the thread on which it is invoked,
to begin the process of terminating the thread. Calling this method
usually terminates the thread."
I've had a long discussion with someone on not to use the mentioned
method unless under the most extreme cases. I believe that it's
|
by: anoop23 |
last post by:
Hi,
Im running a timer to Unzip a zip file using a 'ICSharpCode.SharpZipLib.dll'.
It works well when I block the main thread indefinitely by 'thread.sleep(-1)'.
But gets an ThreadAbort Exception if i run the timer without thread blocking.
How can i avoid this error?Im not using thread.abort anywhere in my
code.My code to unzip file is taking only 6 sec to complete.
Below im showing the code.
|
by: =?Utf-8?B?R2lkaQ==?= |
last post by:
Hi,
In my Windows application, I'm using thread, and I've 2 questions:
1. I read that it's not recommended to use Thread.Abort(), so what is the
best way to close the thread, in case the user wants to cancel or the thread
is finished and i want to close my application?
2. in my Thread I'm creating a dataGridView with DataTable as dataSoruce,
and I've problem with the scroll bars, I see the scroll bars but both of the
|
by: raghudr |
last post by:
Hi all,
I am implemeting a splash screen in C#
I got a useful link from here :-
http://www.codersource.net/csharp_splash_screen.aspx
//Logic when to display a splash screen is:-
Splash screen should start
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |