|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Threading IssueI have a Thread, MainThread, and a child thread that is started in the MainThread called ChildThread. I have a DataSet created in the MainThread in which needs to be passed to the ChildThread. The ChildThread needs to update the DataSet with new data. The MainThread, after the ChildThread is finished, needs to continue on it's merry way updating the DataSet. Part #2: I have MainThread and ChildThread ... in ChildThread, I need to create a DataSet and/or a DataTable. The DataSet then needs to be passed to the MainThread and then bound to either a DataGrid or Crystal Report... I have tried both of the above questions but seem to get the same result every time. Something about can't reference an object created on a different thread. It was some time ago, and I just remembered about it and am now curious. I can try setting up a project and duplicating my problems again if need be...but hopefully there is a short/semi-short method that can be described using pseudo/semi-pseudo code... The problem is for C# or VB.Net, either will solve for the other...as it should be, if any examples/code is given. Thanks! Mythran This seems like homework.
Do you want us to solve your homework for you? Show quoteHide quote "Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message news:OkpdfdBWFHA.3280@TK2MSFTNGP09.phx.gbl... > Part #1: > I have a Thread, MainThread, and a child thread that is started in the > MainThread called ChildThread. > > I have a DataSet created in the MainThread in which needs to be passed to > the ChildThread. The ChildThread needs to update the DataSet with new data. > The MainThread, after the ChildThread is finished, needs to continue on it's > merry way updating the DataSet. > > > Part #2: > I have MainThread and ChildThread ... in ChildThread, I need to create a > DataSet and/or a DataTable. The DataSet then needs to be passed to the > MainThread and then bound to either a DataGrid or Crystal Report... > > I have tried both of the above questions but seem to get the same result > every time. Something about can't reference an object created on a > different thread. It was some time ago, and I just remembered about it and > am now curious. I can try setting up a project and duplicating my problems > again if need be...but hopefully there is a short/semi-short method that can > be described using pseudo/semi-pseudo code... > > The problem is for C# or VB.Net, either will solve for the other...as it > should be, if any examples/code is given. > > Thanks! > > Mythran > "Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message Take a look at this...not a difficult job i think:news:OkpdfdBWFHA.3280@TK2MSFTNGP09.phx.gbl... > Part #1: > I have a Thread, MainThread, and a child thread that is started in the > MainThread called ChildThread. > > I have a DataSet created in the MainThread in which needs to be passed to > the ChildThread. The ChildThread needs to update the DataSet with new > data. The MainThread, after the ChildThread is finished, needs to continue > on it's merry way updating the DataSet. /////////////////////////////////////////////////////////// class Application { void MainJob() { Thread.CurrentThread.Name = "Main thread"; ds = new DataSet(); ds.Create(); Thread th = new Thread(new ThreadStart(this.ChildJob)); th.Name = "Child thread"; th.Start(); th.Join(); ds.Update(); //.... } void ChildJob() { ds.Update(); } DataSet ds; // a shared dataset } } public class DataSet { public DataSet() { Console.WriteLine("Dateset instantiated on thread: {0}", Thread.CurrentThread.Name); } public void Create() { Console.WriteLine("DataSet created on thread: {0}" , Thread.CurrentThread.Name); } public void Update() { Console.WriteLine("DataSet updated on thread: {0}", Thread.CurrentThread.Name); } } /////////////////////////////////////////////// If you are afraid of multiple access to your dataset by many thread, simply use the lock(this) statement (Monitor.Enter(....) and Monitor.Exit() in VB)
What is your weightage of the 3 characteristics of Object-Oriented Programming....
Formatting Currency End Processes How to protect my data in Executable file? SQL Querry question Looking for a better way to compress images. Disable the popup security message from Outlook2003. Assembly location Menu hot-keys don't underline Open & Read Excel files from VB.NET |
|||||||||||||||||||||||