473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

object lifetime question

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
3 1082

"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
David,

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

Cor
Nov 16 '05 #3

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1277
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
3724
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
2924
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
3124
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...
3
1130
by: Bob Altman | last post by:
Hi all, I have a basic question regarding holding references to objects in unmanaged C++. Suppose my unmanaged C++ class has a method that accepts a reference to an object as an argument, and...
5
2495
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: ...
17
2569
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do...
10
2560
by: njk966 | last post by:
I have a dynamically loaded control that queries a database and fills the results into a new object. Class Person ...class properties ...class methods End Class Dim Person As New Person...
0
1293
by: Stodge | last post by:
Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working...
6
1522
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
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
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,...
1
6878
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
5456
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,...
1
4897
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...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.