473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Connection Instance Members are not thread safe question.

I have a winform in .NET 2.0 that uses will require the use of a
backgroundWorker thread due to the long processing time of one Command
.. I have a data provider whose Connection class is not thread safe. I
would like to know what the _best_ way to implement this is. Do I
create a copy constructor for the Connection class and create a new
instance for the Connection that will be used in the threaded function?
regards,
karen

Jan 23 '07 #1
2 2408

I wouldn't really expect a connection to be thread-safe.
Personally I'd let the data-access code worry about their own
connections from a connection-string (or named key), and let the
ADO.Net connection pooling worry about the rest (making sure I use
"using" etc). As long as each connection / command is local to a thread
(and/or method block) then thread safety isn't an issue... however, you
must be aware of transactional issues, especially if you are directly
competing for data; you can either block or deadlock yourself very
easily.

Was this the question, or am I off to one side?

Marc

Jan 23 '07 #2
I think Marc pretty much hit on the gist of this. The key concept here is
"what kind of connection" are we talking about. If it is an SqlClient
SqlConnection, you should be more concerned with whether it will be correctly
Connection Pooled rather than worrying about whether it is threadsafe or that
you might need copy constructors.

post some sample code, and we'll try to help nail down the basics for you.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Karen Hill" wrote:
I have a winform in .NET 2.0 that uses will require the use of a
backgroundWorker thread due to the long processing time of one Command
.. I have a data provider whose Connection class is not thread safe. I
would like to know what the _best_ way to implement this is. Do I
create a copy constructor for the Connection class and create a new
instance for the Connection that will be used in the threaded function?
regards,
karen

Jan 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: meng | last post by:
is it possible to use a single connection object shared by several tasks where each task is handled by a thread? these tasks call stored procedures that return record sets, no editing, update or...
5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
4
by: MikeAth via DotNetMonster.com | last post by:
Hi all, I have two different classes and one instance of the Form. I would like to access the members of the Form instance in both classes without having to create a new instance in the other...
10
by: Daniel Fernandes | last post by:
Hi there Let's say due to several reasons I have an ASP.Net application that has a database access class that stores a database connection in a shared member : public class dataaccess ...
29
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's...
8
by: nytimescnn | last post by:
I've read some discuession about lock() for thread-safe. I am wondering what will be the differce between below two code segment? Code 1: class A { private static Object padlock = new...
8
by: esha | last post by:
I was suggested by a member of this group not to use global connection object. Instead of it I was suggested to create a new one in every procedure and close it at the end of that procedure. What...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...

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.