473,657 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1943
Charlie Brown <cb****@duclaw. comwrote in news:1194892903 .889392.257060
@v65g2000hsc.go oglegroups.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...@r ogers.comwrote:
Charlie Brown <cbr...@duclaw. comwrote in news:1194892903 .889392.257060
@v65g2000hsc.go oglegroups.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.Exec uteNonQuery 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.goo glegroups.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.Exec uteNonQuery 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
4102
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 done after blessing) between all of the mod_perl2 threads. The structure can grow quite big - tenths of thousands of array elements. It can grow as system operates (not possible to construct at apache startup). Sharing array is OK, but inserting...
1
1614
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 requirement to 'share' some data values between these script instances (e.g. counters, file handles etc).
6
5896
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= 2005-07-28-10.39.02.015001 Instance:DB2 Node:000 PID:1568(db2syscs.exe) TID:2440 Appid:0A00153A.C90B.050728083720
4
5283
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 time a thread try to do something with the file, the thread will create a new file handle. However, if I specify FileShare.ReadWrite, other process can also open that file. I tried FileShare.Inheritable but it doesn't work. The reason I needs to...
0
2419
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 problem i have by doing try..catch like this : (Generate when xmlDoc.Save(filename) is called) 1. The process cannot access the file "C:\Files\Monitor.xml" because it is being used by another process. and the stack trace :
3
2216
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 same file stream. I was going to pass a ref to the file stream to the second thread, but the problem comes when I am trying to read from one section of the stream and write to another. I dont want one thread changing the position of the stream...
6
3069
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 (using TextWriter.Synchronized) for writing data to the text file. The class in the DLL (LogManagement) is implemented using the Singleton pattern. My problem is that when I try to write data from more that one executables
19
6332
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 can all access. It seems like a needless waste of memory to make them all maintain their own copy of the same data in RAM at the same time. What's the best way to achieve this? I've heard of memory mapped files, so maybe that's the answer. ...
3
1414
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
8833
Oralloy
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...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 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...
0
7345
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, 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...
1
6174
isladogs
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...
0
5636
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();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.