473,385 Members | 1,908 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,385 software developers and data experts.

Sharing Data between threads

I have an application that loops through a dataset and retrieves /
updates information in rows that meet certain criteria. When the end
user clicks a button, the dataset is then merged with the database. I
would like to make the merge process run in the background so that no
user interaction is required. I can make the background thread run
and update the dataset just fine. My questions are, can 2 threads
loop through a dataset at the same time? Can my background process
create a copy of the database and then merge the copy? Can my
background process download a new set of data and copy it over the
current dataset?

Any help is much appreciated.

Nov 12 '07 #1
3 1925
Charlie Brown <cb****@duclaw.comwrote in news:1194892903.889392.257060
@v65g2000hsc.googlegroups.com:
My questions are, can 2 threads
loop through a dataset at the same time?
Yes, but you'll have to deal with concurrency issues. If two threads are
updating the data, which thread takes precendence? What if two threads
updating the same field at the same time?
Can my background process
create a copy of the database and then merge the copy?
How large is your database? What sort of updates are you applying?
Can my
background process download a new set of data and copy it over the
current dataset?
Yes, but you'll need to deal with concurrency issues.

Nov 12 '07 #2
On Nov 12, 3:41 pm, Spam Catcher <spamhoney...@rogers.comwrote:
Charlie Brown <cbr...@duclaw.comwrote in news:1194892903.889392.257060
@v65g2000hsc.googlegroups.com:
My questions are, can 2 threads
loop through a dataset at the same time?

Yes, but you'll have to deal with concurrency issues. If two threads are
updating the data, which thread takes precendence? What if two threads
updating the same field at the same time?
Can my background process
create a copy of the database and then merge the copy?

How large is your database? What sort of updates are you applying?
Can my
background process download a new set of data and copy it over the
current dataset?

Yes, but you'll need to deal with concurrency issues.
Thanks for the reply. The dataset is small, say around 2000 rows, 6
columns, max. The UI searches for a specific row every few seconds
and updates a boolean value. The background task loops through the
dataset at a set interval and updates the database by calling
SqlCommand.ExecuteNonQuery on the rows that have been affected. Once
all affected rows have been updated, it creates a new dataset and then
copies over the original.

The only problem with this approach would be if the UI updates the
dataset after the merge completes, but before the new data is copied
down from the database. Basically I would lose that data.

Nov 12 '07 #3
Charlie Brown <cb****@duclaw.comwrote in news:1194901576.798306.28180
@v2g2000hsf.googlegroups.com:
Thanks for the reply. The dataset is small, say around 2000 rows, 6
columns, max. The UI searches for a specific row every few seconds
and updates a boolean value. The background task loops through the
dataset at a set interval and updates the database by calling
SqlCommand.ExecuteNonQuery on the rows that have been affected. Once
all affected rows have been updated, it creates a new dataset and then
copies over the original.
Datasets provide events for changed rows/columns/cells. Perhaps you can
hook into these events to act on the changes rather than polling on the
dataset?
The only problem with this approach would be if the UI updates the
dataset after the merge completes, but before the new data is copied
down from the database. Basically I would lose that data.
You'll need to do some synclocking to prevent concurrency issues.

Nov 13 '07 #4

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

Similar topics

1
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing...
1
by: adsheehan | last post by:
Hi, I have a multi-threaded C++ software app that embeds Python. When multi-threading (native system threads) it is possible that multiple instances of a Python script are active. I have a...
6
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= ...
4
by: Tony Liu | last post by:
Hi, how can I create multiple new file handles of a file without having to share to file to the other processes? I have a file that will be accessed by multiple threads in my application, each...
0
by: Raed Sawalha | last post by:
Dear: I have windows application that running multiple threads( using ThreadPool.QueueUserWorkItem) , all threads designed to write the same XML file, and update same SQL Server Table , the...
3
by: frustrated | last post by:
I am trying to share a file stream between two threads, but havent got a clue as to how to do it. The first thread will be reading the file, and the second thread will(/might) be writing to the...
6
by: Rajesh | last post by:
Hi, We are tyring to build a DLL which will write the log data to a text file. Multiple executables should use this dll to write data to same text file. We are using a synchronized method...
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
3
by: =?Utf-8?B?SXNsYXkgUm9kcmlndWV6IEpyLg==?= | last post by:
How do you share glogal data stuctures between VB.net and C++ or C# ? Thanks, Islay -- Islay
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
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
BarryA
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...
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
marktang
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,...
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...

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.