New to multi-threading (less than 24 hours at it <grin>)
Anyway, it's all making sense, and working fairly well
thus far, but I'm having a minor issue I'm not sure how
to get around.
I've got a form that uses SqlDataAdapter. It fires off
a thread to fill a DataSet. Not a big deal, this works.
I've also got a requirement that the Thread that's going
off to do the work -- if it takes too long, it has to
honor a timeout, or a cancellation request from the
user.
No problems here, I've got them both done and working
to where they kill the Thread (Thread.Abort()). The
problem is, that killing the Thread leaves the SqlDataAdapter
in an inconsistent state, in particular, the SqlConnection
for the Procedures (InsertProcedure, UpdateProcedure, etc) --
the SqlConnection is still open, but hosed and can't be
re-used.
If I try to .Close() it, I get an error. It can't be closed.
What I've done is to, just prior to the Thread.Abort(), I
issue a Cancel() on the Command object. This seems to have
fixed most of the issue, but not all. The Cancel() appears
to only *attempt* a true cancel of the command, and is not
actually successful every time. Of course, the other issue
is that .Cancle returns void, so I don't have a return
value to check if it actually was successful.
So, I do
theCommand.Cancel()
Thread.Abort()
and hope that the Command gets cancelled. Sometimes it's
not. This leaves me holding the bag, as the next time
the Adapter attempts to do something on that connection,
it's hosed. There's a lot of data access going on with
this form, so I keep reusing the same connection. That
gets to be a problem when you try to reuse a hosed
connection.
Are you following me on this?
What's a guy to do? 2 2466
I don't think aborting a thread like this is a good idea (I've been through
the wringer with almost exactly the same issue). I think aborting any .NET
thread that is making use of COM resources is generally considered bad
practice with unpredictable results. Cancel the command by all means, but
let the thread run through to terminate normally.
"Sgt. Sausage" <no****@nowhere.com> wrote in message
news:3b**************************@FUSE.NET... New to multi-threading (less than 24 hours at it <grin>)
Anyway, it's all making sense, and working fairly well thus far, but I'm having a minor issue I'm not sure how to get around.
I've got a form that uses SqlDataAdapter. It fires off a thread to fill a DataSet. Not a big deal, this works. I've also got a requirement that the Thread that's going off to do the work -- if it takes too long, it has to honor a timeout, or a cancellation request from the user.
No problems here, I've got them both done and working to where they kill the Thread (Thread.Abort()). The problem is, that killing the Thread leaves the SqlDataAdapter in an inconsistent state, in particular, the SqlConnection for the Procedures (InsertProcedure, UpdateProcedure, etc) -- the SqlConnection is still open, but hosed and can't be re-used.
If I try to .Close() it, I get an error. It can't be closed.
What I've done is to, just prior to the Thread.Abort(), I issue a Cancel() on the Command object. This seems to have fixed most of the issue, but not all. The Cancel() appears to only *attempt* a true cancel of the command, and is not actually successful every time. Of course, the other issue is that .Cancle returns void, so I don't have a return value to check if it actually was successful.
So, I do
theCommand.Cancel() Thread.Abort()
and hope that the Command gets cancelled. Sometimes it's not. This leaves me holding the bag, as the next time the Adapter attempts to do something on that connection, it's hosed. There's a lot of data access going on with this form, so I keep reusing the same connection. That gets to be a problem when you try to reuse a hosed connection.
Are you following me on this?
What's a guy to do?
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:d6*******************@news.demon.co.uk... I don't think aborting a thread like this is a good idea (I've been through the wringer with almost exactly the same issue). I think aborting any .NET thread that is making use of COM resources is generally considered bad practice with unpredictable results. Cancel the command by all means, but let the thread run through to terminate normally.
Yeah, I suppose that's the route to go.
I'll have to change a few things to do this, but it's TheRightThingToDo(tm). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rob |
last post by:
Hello,
I've got an issue where a process in a third party application has a dll
which while exiting sort of freezes and runs away with processor cycles.
i've written a block of code so that I...
|
by: Mike |
last post by:
We are intermitantly receiving this error on our website.
ExecuteReader requires an open and available Connection. The connection's
current state is connecting. Following is the code from the Load...
|
by: rn5a |
last post by:
The following code resides in a VB class file name GetOrder.vb (this
class file exists in the App_Code directory):
Namespace Shop
Public Class Orders
Public Function ViewOrder(ByVal UserID As...
|
by: Fendi Baba |
last post by:
I created an ASP.net page which opens excel. This works fine in Office
2007. However, Excel 2003 runs in an error which states "cannot read
output file".
Hee is the VB code and below is the ASPX...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| | |