472,959 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 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 1098
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: johny smith | last post by:
Suppose there is a policy that all objects are statically declared. For example: static Car car(); Then, is there a reason to have a destructor defined for the class Car. It would seem...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
8
by: pt | last post by:
Hallo, i wonder how it is going to be of this code below regarding of the return of temporary object. Prototypes: =========== bool Activation(TCHAR *c); std::basic_string<TCHAR> GetFile();
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
3
by: nagashre | last post by:
class A { public: A():a(0), b(0){} handleMyMsg( char* aa, char*bb); private: processMessage();
6
by: better_cs_now | last post by:
Hello all, class Foo {/* Details don't matter */}; class Bar { public: Bar(): m_Foo(/* Construct a Foo however it wants to be constructed */); const Foo &GetFoo() const { return m_Foo; }...
6
by: Rajesh | last post by:
I read Global Object's constructor will be called before main() function; In which situation it can be really helpful? Is it good practice use Global object and its constructor ? Thanks,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.