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

Program flow with multi-threading app - corrupted datatables

Hi,

I am building a windows app. I have two threads that continually run
in the background pulling information from a website. The data I
extract from the two separate threads needs to be put into various
columns of the same datatable (which is defined in a dataset on my form
in design time). The threads take different amounts of time to cycle
so the updates to the datatable frequently overlap.

I have run into various issues in the that the datatable frequently
becomes corrupted by doing this (datatable internal index is
corrupted:13 message). I am not sure if this is the result of
simultaneous updates / lockings or trying to access the datatable from
the worker threads.

I would be grateful if you could let me know the correct way of
updating this datatable. Should I be passing the returned data back to
the thread that the datatable is on before trying to update it? If so
how would I do this? Also, are there any other considerations I am
missing in terms of the program design?

Thank you very much,

Mike

Jul 21 '06 #1
4 3549
Mike,

As long as you do not show the datatable in a UI and do synclock the adding
of the newrows there should not be any problem.

The only thing can be that it takes a little bit long, so I would put a
Queue between it.

Cor
"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi,

I am building a windows app. I have two threads that continually run
in the background pulling information from a website. The data I
extract from the two separate threads needs to be put into various
columns of the same datatable (which is defined in a dataset on my form
in design time). The threads take different amounts of time to cycle
so the updates to the datatable frequently overlap.

I have run into various issues in the that the datatable frequently
becomes corrupted by doing this (datatable internal index is
corrupted:13 message). I am not sure if this is the result of
simultaneous updates / lockings or trying to access the datatable from
the worker threads.

I would be grateful if you could let me know the correct way of
updating this datatable. Should I be passing the returned data back to
the thread that the datatable is on before trying to update it? If so
how would I do this? Also, are there any other considerations I am
missing in terms of the program design?

Thank you very much,

Mike

Jul 21 '06 #2
Thanks for replying Cor. Apologies but I forgot to mention that I have
this datatable bound to a datagridview on the form. Assuming this is
the problem, would the synclock solution still work? I thought that
these kinds of updates were not thread safe and this is probably why it
is crashing.

Thanks again for any help,

Mike

Cor Ligthert [MVP] wrote:
Mike,

As long as you do not show the datatable in a UI and do synclock the adding
of the newrows there should not be any problem.

The only thing can be that it takes a little bit long, so I would put a
Queue between it.

Cor
"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi,

I am building a windows app. I have two threads that continually run
in the background pulling information from a website. The data I
extract from the two separate threads needs to be put into various
columns of the same datatable (which is defined in a dataset on my form
in design time). The threads take different amounts of time to cycle
so the updates to the datatable frequently overlap.

I have run into various issues in the that the datatable frequently
becomes corrupted by doing this (datatable internal index is
corrupted:13 message). I am not sure if this is the result of
simultaneous updates / lockings or trying to access the datatable from
the worker threads.

I would be grateful if you could let me know the correct way of
updating this datatable. Should I be passing the returned data back to
the thread that the datatable is on before trying to update it? If so
how would I do this? Also, are there any other considerations I am
missing in terms of the program design?

Thank you very much,

Mike
Jul 21 '06 #3
Mike,

I have no time now anymore to make a sample (and try it), but when I would
make your solution than.

I would use the queue class (you know what that is in Britain, I have
refreshed my knowledge of that in a Holiday there last week).

http://msdn2.microsoft.com/en-us/lib...ons.queue.aspx

Let the threads fill (enqueue) the queue with datarows while synclocking it.

Than I would use a forms timer and set that to about 5 or 10 seconds
whatever you like.

Than I would add those datarows using that queue class (dequeue) into the
datatable in the timer event, what has as well has to be done synclocked.

At the end of my timer event I would refresh my datagridview.

I think that this does not even need much changes in your program.

I hope this helps,

Cor

"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks for replying Cor. Apologies but I forgot to mention that I have
this datatable bound to a datagridview on the form. Assuming this is
the problem, would the synclock solution still work? I thought that
these kinds of updates were not thread safe and this is probably why it
is crashing.

Thanks again for any help,

Mike

Cor Ligthert [MVP] wrote:
>Mike,

As long as you do not show the datatable in a UI and do synclock the
adding
of the newrows there should not be any problem.

The only thing can be that it takes a little bit long, so I would put a
Queue between it.

Cor
"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11**********************@i3g2000cwc.googlegr oups.com...
Hi,

I am building a windows app. I have two threads that continually run
in the background pulling information from a website. The data I
extract from the two separate threads needs to be put into various
columns of the same datatable (which is defined in a dataset on my form
in design time). The threads take different amounts of time to cycle
so the updates to the datatable frequently overlap.

I have run into various issues in the that the datatable frequently
becomes corrupted by doing this (datatable internal index is
corrupted:13 message). I am not sure if this is the result of
simultaneous updates / lockings or trying to access the datatable from
the worker threads.

I would be grateful if you could let me know the correct way of
updating this datatable. Should I be passing the returned data back to
the thread that the datatable is on before trying to update it? If so
how would I do this? Also, are there any other considerations I am
missing in terms of the program design?

Thank you very much,

Mike

Jul 21 '06 #4
Yes we love our queues :-) I hope you enjoyed your stay.

The synclock on its own was enough to fix this problem - the majority
of the updates to the datatable were value updates rather than row
additions.
Using synclock slowed down the app quite a bit (I have to lock the
table 2-3 times per datarefresh, datarefresh is 2 times per second).
I don't yet understand all the details as I'm still quite an amateur
but using a delegate from the worker thread to make all the changes to
the datatable (including the use of the synclock) works excellently.
The time difference was roughly 50ms vs 500ms without delegate. I
guess there is a very good reason for this.

Incredibly happy to have solved the problem and really appreciate the
help!

Thank you,

Mike

Cor Ligthert [MVP] wrote:
Mike,

I have no time now anymore to make a sample (and try it), but when I would
make your solution than.

I would use the queue class (you know what that is in Britain, I have
refreshed my knowledge of that in a Holiday there last week).

http://msdn2.microsoft.com/en-us/lib...ons.queue.aspx

Let the threads fill (enqueue) the queue with datarows while synclocking it.

Than I would use a forms timer and set that to about 5 or 10 seconds
whatever you like.

Than I would add those datarows using that queue class (dequeue) into the
datatable in the timer event, what has as well has to be done synclocked.

At the end of my timer event I would refresh my datagridview.

I think that this does not even need much changes in your program.

I hope this helps,

Cor

"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks for replying Cor. Apologies but I forgot to mention that I have
this datatable bound to a datagridview on the form. Assuming this is
the problem, would the synclock solution still work? I thought that
these kinds of updates were not thread safe and this is probably why it
is crashing.

Thanks again for any help,

Mike

Cor Ligthert [MVP] wrote:
Mike,

As long as you do not show the datatable in a UI and do synclock the
adding
of the newrows there should not be any problem.

The only thing can be that it takes a little bit long, so I would put a
Queue between it.

Cor
"Mike" <my***@pearcey2001.freeserve.co.ukschreef in bericht
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi,

I am building a windows app. I have two threads that continually run
in the background pulling information from a website. The data I
extract from the two separate threads needs to be put into various
columns of the same datatable (which is defined in a dataset on my form
in design time). The threads take different amounts of time to cycle
so the updates to the datatable frequently overlap.

I have run into various issues in the that the datatable frequently
becomes corrupted by doing this (datatable internal index is
corrupted:13 message). I am not sure if this is the result of
simultaneous updates / lockings or trying to access the datatable from
the worker threads.

I would be grateful if you could let me know the correct way of
updating this datatable. Should I be passing the returned data back to
the thread that the datatable is on before trying to update it? If so
how would I do this? Also, are there any other considerations I am
missing in terms of the program design?

Thank you very much,

Mike
Jul 21 '06 #5

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

Similar topics

3
by: Albert Ahtenberg | last post by:
Hello, I had some bad experience with code organization and script functionality in writing my php based applications. And as the applications get bigger in scale it gets even worse. Therefore,...
4
by: Bruce W...1 | last post by:
A scripting newbie question... I'm trying to understand some code I found. This script conducts a poll and writes the results to a text file. The following statement is part of the source file. ...
1
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? ...
3
by: Pat Deegan | last post by:
Greetings, I've been having issues while debugging programs. The problems only appear when using the '-d' switch and I get the impression it has to do with UTF8 and regex matching but I don't...
2
by: Andrew Daviel | last post by:
I'd like to know how I can create a flow of 2-row elements that is resized by the browser window. I.e., I want to bind elements together (in a div, or table, or something) and then treat the...
7
by: jacob navia | last post by:
Suppose that you want to know where your program has passed, i.e. the exact flow of the program. A brute force solution is to make an array of n lines, n being the number of lines in the...
1
by: Brett | last post by:
I'd like to have all of my documentation in one place. I use the following for documenting code: - attributes for certain types of documentation - use of the C# generated inline XML...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
6
by: Crooter | last post by:
Hello colleagues, Could anybody tell me if there are existing open-source solutions to extract the program tree using a program source code? I'm aware that GCC has program flow information and...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
isladogs
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...
0
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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...

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.