471,356 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

object lifetime

hi,
i have problem about object references,,

lets say: i have a typed dataset (name: "dsall")
it has datatables table1 , table2
there are dataadapters which fills these and there are also
datagrids,comboboxes etc which are binded to this dataset

then i write this code to FORM_LOAD

//create thread in order not to wait getting process

private void formload(.......,.....)
{

Thread thr =new Thread(new ThreadStart(xx));
thr.isBackGround = true;
thr.Start();

//other things
}

private void xx()
{
adapter1.Fill(dsAll.Table1);
adapter1.Fill(dsAll.Table2);
//etc etc..
}

here is problem
when this code is executed, Null Reference exception is thrown

as i understand adapter1 creates datatable in thread scope and because
thread is ended, garbage collector collects datatable so i get null
reference exception, i say this because if i use this form there is no
error.

private void formload(.......,.....)
{

//dont use thread
//Thread thr =new Thread(new ThreadStart(xx));
//thr.Start();
//call directly function
xx();

//other things
}

but i need to fill dataset with thread

Thanks in advance

Erdem...
Jul 21 '05 #1
3 1067
Erdem,

An object lives as long as there is an reference to is.

In my opinion is propably your problem that when the dataset is needed in
thread A, it is still busy to be created in thread B.

Just my thought,

Cor
Jul 21 '05 #2
Cor Ligthert wrote:
Erdem,

An object lives as long as there is an reference to is.

In my opinion is propably your problem that when the dataset is needed in
thread A, it is still busy to be created in thread B.

Just my thought,

Cor

Hi Cor,

thanks for your advice,

i thought as you thought and tried to give datasource of controls at
thread b so that thread A will no longer need it, while thread B is
processing dataset. but there appeared another problem,
you cant give datasource of control in another thread (other than main
thread i think)
so i saw i should give datasource within main thread

so i found new solution
i use begin invoke method so that controls datasource is given within
main thread and does processing at background...

thank you

Erdem
Jul 21 '05 #3
Cor... If I may clarify. An object is eligible for garbage collection
when it is unreachable. It is a feature of C# that two objects with
references to each other (circular references) may be eligible for
garbage collection if both objects are unreachable.

Regards,
Jeff
An object lives as long as there is an reference to is.<


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by johny smith | last post: by
5 posts views Thread by Michael Moreno | last post: by
16 posts views Thread by anonymous.user0 | last post: by
3 posts views Thread by nagashre | last post: by
6 posts views Thread by better_cs_now | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.