By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,458 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,458 IT Pros & Developers. It's quick & easy.

object lifetime question

P: n/a
hi again,

here is my problem again:

i have a typed dataset dsA;
an adapter adapterA;

here is structure

mydataset dsA;
odbcdataadapter adapterA;
.....
.....

private form_Load(object sender, System.EventArgs e)
{
Thread thr;
thr = new Thread(new ThreadStart(PreLoader));
thr.IsBackground = false;
thr.Start();
}

private void PreLoader()
{
adapterA.Fill(dsA);
....
....
...

//Here Thread Ends.
}

Also there are some Datagrids whose datasource is dsA.TableX

After program runs, it works normally for a few time then an
NullRefernce Exception is thrown.

i think, it is because, the created thread ended and we filled dsA in
scope of that thread so garbage collector collect memory area.
WHY this happens, or what can i do to correct this problem.

need help

Thanks
erdem
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"erdem" <er***@kulube.net> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
hi again,

here is my problem again:

i have a typed dataset dsA;
an adapter adapterA;

here is structure

mydataset dsA;
odbcdataadapter adapterA;
....
....

private form_Load(object sender, System.EventArgs e)
{
Thread thr;
thr = new Thread(new ThreadStart(PreLoader));
thr.IsBackground = false;
thr.Start();
}

private void PreLoader()
{
adapterA.Fill(dsA);
....
....
...

//Here Thread Ends.
}

Also there are some Datagrids whose datasource is dsA.TableX

After program runs, it works normally for a few time then an NullRefernce
Exception is thrown.

i think, it is because, the created thread ended and we filled dsA in
scope of that thread so garbage collector collect memory area.


No, that doesn't make any sense. It's more likely because PreLoader hasn't
run or hasn't finished when you try to DataBind the grids.

It's fine to fill the DataSet on a background thread, but you make sure that
the background thread has finished before you use the DataSet. An easy way
to do this is to keep a form-level reference to the background thread and
call Thread.Join to wait for PreLoader to finish just before you data bind
the grids.

David
Nov 16 '05 #2

P: n/a
David,

That was my idea as well, however what is than the sence of the thread.

Cor
Nov 16 '05 #3

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
David,

That was my idea as well, however what is than the sence of the thread.

Cor


You can do extra work and maintain UI responsiveness between Thread.Start
and Thread.Join.

David
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.