473,398 Members | 2,404 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,398 software developers and data experts.

Synchronized dataset

I have in a form a datagrid that display a dataset, but if I start a new
thread that fill the dataset the program will crash, that's because the
dataset is not synchronized, is not thread safe.
I tryed to use the monitor.enter(dataset) and monitor.exit(dataset) befor
updating the dataset but was useless.
I think the problem is the paint method of the datagrid, that you can not
override, so you can not synchronize the dataset.
Also there is only one paint event, you need at least two, one befor and one
after painting.

Someone has a suggestion?
Nov 15 '05 #1
4 4028
Zurcher,

The problem is not that the data set is not synchronized, but when you
bind the data set to a grid, then the grid sets up event handlers on the
data set. When you change the data, the events fire, and the grid tries to
update itself. If you want to do anything that affects the state of the UI,
then that call must be made on the UI thread. What you need to do is
marshal the call to the UI thread. In order to do this, create a method
which will change your data. Then create a delegate which matches the
signature of that method. Once you have that, on your thread that is
performing the calcs, call the Invoke method on the grid, passing the
delegate wrapping the method, and any parameters you need to pass.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
I have in a form a datagrid that display a dataset, but if I start a new
thread that fill the dataset the program will crash, that's because the
dataset is not synchronized, is not thread safe.
I tryed to use the monitor.enter(dataset) and monitor.exit(dataset) befor
updating the dataset but was useless.
I think the problem is the paint method of the datagrid, that you can not
override, so you can not synchronize the dataset.
Also there is only one paint event, you need at least two, one befor and one after painting.

Someone has a suggestion?

Nov 15 '05 #2
Thank's, I'll try.
Can I ask you something else, there is a difference between this two way to
start a new thread (to do not use that from the UI):

System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(this.MyFunction),nul l);

or

System.Threading.Thread tNewThread=new System.Threading.Thread(new
System.Threading.ThreadStart(this.MyFunction));
tNewThread.Start();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:ey**************@TK2MSFTNGP12.phx.gbl...
Zurcher,

The problem is not that the data set is not synchronized, but when you
bind the data set to a grid, then the grid sets up event handlers on the
data set. When you change the data, the events fire, and the grid tries to update itself. If you want to do anything that affects the state of the UI, then that call must be made on the UI thread. What you need to do is
marshal the call to the UI thread. In order to do this, create a method
which will change your data. Then create a delegate which matches the
signature of that method. Once you have that, on your thread that is
performing the calcs, call the Invoke method on the grid, passing the
delegate wrapping the method, and any parameters you need to pass.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
I have in a form a datagrid that display a dataset, but if I start a new
thread that fill the dataset the program will crash, that's because the
dataset is not synchronized, is not thread safe.
I tryed to use the monitor.enter(dataset) and monitor.exit(dataset) befor updating the dataset but was useless.
I think the problem is the paint method of the datagrid, that you can not override, so you can not synchronize the dataset.
Also there is only one paint event, you need at least two, one befor and

one
after painting.

Someone has a suggestion?


Nov 15 '05 #3
Zurcher,

Generally speaking, the ThreadPool should be used, as it eliminates the
overhead of having to create a thread every time you want to perform a
finite task. If you needed a thread which ran in a loop, over and over,
then you would create a new instance of the Thread class. However, if you
just want to perform a finite task asynchronously, then you would use the
ThreadPool class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
Thank's, I'll try.
Can I ask you something else, there is a difference between this two way to start a new thread (to do not use that from the UI):

System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(this.MyFunction),nul l);

or

System.Threading.Thread tNewThread=new System.Threading.Thread(new
System.Threading.ThreadStart(this.MyFunction));
tNewThread.Start();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:ey**************@TK2MSFTNGP12.phx.gbl...
Zurcher,

The problem is not that the data set is not synchronized, but when you
bind the data set to a grid, then the grid sets up event handlers on the
data set. When you change the data, the events fire, and the grid tries

to
update itself. If you want to do anything that affects the state of the

UI,
then that call must be made on the UI thread. What you need to do is
marshal the call to the UI thread. In order to do this, create a method
which will change your data. Then create a delegate which matches the
signature of that method. Once you have that, on your thread that is
performing the calcs, call the Invoke method on the grid, passing the
delegate wrapping the method, and any parameters you need to pass.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
I have in a form a datagrid that display a dataset, but if I start a new thread that fill the dataset the program will crash, that's because the dataset is not synchronized, is not thread safe.
I tryed to use the monitor.enter(dataset) and monitor.exit(dataset) befor updating the dataset but was useless.
I think the problem is the paint method of the datagrid, that you can not override, so you can not synchronize the dataset.
Also there is only one paint event, you need at least two, one befor

and one
after painting.

Someone has a suggestion?



Nov 15 '05 #4
Thanks for everything

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:ug**************@tk2msftngp13.phx.gbl...
Zurcher,

Generally speaking, the ThreadPool should be used, as it eliminates the overhead of having to create a thread every time you want to perform a
finite task. If you needed a thread which ran in a loop, over and over,
then you would create a new instance of the Thread class. However, if you
just want to perform a finite task asynchronously, then you would use the
ThreadPool class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
Thank's, I'll try.
Can I ask you something else, there is a difference between this two way

to
start a new thread (to do not use that from the UI):

System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(this.MyFunction),nul l);

or

System.Threading.Thread tNewThread=new System.Threading.Thread(new
System.Threading.ThreadStart(this.MyFunction));
tNewThread.Start();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schrieb
im Newsbeitrag news:ey**************@TK2MSFTNGP12.phx.gbl...
Zurcher,

The problem is not that the data set is not synchronized, but when you bind the data set to a grid, then the grid sets up event handlers on the data set. When you change the data, the events fire, and the grid tries to
update itself. If you want to do anything that affects the state of
the
UI,
then that call must be made on the UI thread. What you need to do is
marshal the call to the UI thread. In order to do this, create a
method which will change your data. Then create a delegate which matches the
signature of that method. Once you have that, on your thread that is
performing the calcs, call the Invoke method on the grid, passing the
delegate wrapping the method, and any parameters you need to pass.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zürcher See" <aq****@cannabismail.com> wrote in message
news:10***************@fuchs.cyberlink.ch...
> I have in a form a datagrid that display a dataset, but if I start a

new > thread that fill the dataset the program will crash, that's because the > dataset is not synchronized, is not thread safe.
> I tryed to use the monitor.enter(dataset) and monitor.exit(dataset)

befor
> updating the dataset but was useless.
> I think the problem is the paint method of the datagrid, that you
can not
> override, so you can not synchronize the dataset.
> Also there is only one paint event, you need at least two, one befor

and one
> after painting.
>
> Someone has a suggestion?
>
>



Nov 15 '05 #5

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

Similar topics

2
by: Frank | last post by:
Hi, In the javadocs regarding many of the java.util classes, it states that the classes are not synchronized, and suggest using the Collections.synchronizedX(...) methods for getting...
4
by: Rich Sienkiewicz | last post by:
Some classes, like Queue and SortedList, have a Synchronized method which gives a thread safe wrapper object for these classes. But the lock() statement does the same thing. Is there any rules as to...
4
by: chrisben | last post by:
Hi I often use Queue.Synchronized method to create a queue for multithread writing. I also know I could use SyncRoot and lock to write Queue. Could anyone here please explain to me the pros and...
6
by: rmunson8 | last post by:
I have a derived class from the Queue base class. I need it to be thread-safe, so I am using the Synchronized method (among other things out of scope of this issue). The code below compiles, but...
8
by: ASP.Net programmer | last post by:
Hi, I have a few methods in a class that I want to synchronize (make sure they can't be used at the same time by multiple threads). As a Java programmer I just do this: public synchronized...
0
by: Hubert | last post by:
Hi I created XmlDataDocument synchronized with DataSet. everythingi is grat until I need to clear all data from it. I've tried Reset(), Clear(), RemoveChild etc. but nothing works. The only way I...
1
by: KK | last post by:
Dear All I have a class whose methods are getting called from multiple threads in my application. For example class DataDistribution { private ArrayList datset; public DataDistribution() {...
3
by: Ryan Liu | last post by:
Hi, What does ArrayList.Synchronized really do for an ArrayList? Is that equal to add lock(this) for all its public methods and properties? Not just for Add()/Insert()/Remvoe()/Count, but also...
0
by: tony | last post by:
Hello! Below I have three methods it's SavePost, SavePostSetUpTableFlg and SavePostBlowStepFlg. I want to use transaction to keep the data synchronized. All or nothing must be executed. When...
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: 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
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
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,...
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
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,...
0
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...

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.