473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Threading and Scope

Hi all.
I can't find anything to explain how to prevent losing my object reference.

I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data
and populate the document with a report, then open the document. It all
works great except the document opens and immediately closes.

What I don't understand is this:
If I Dim as New the document object in a function, then process the data
and report in the other class without threading, the document opens and
stays open even though the function is exited and the document object
and other class go out of scope.
But, if I do the same thing using threading, the document and class
still go out of scope, but now I lose the document completely.

Can anyone explain this? Better yet, how to avoid this? Or point me to
a reference?

So frustrating, so frustrating...

Thanks,
Tom
Jul 13 '06 #1
6 1083
It Word document?
"tomb" <to**@technetcenter.comwrote in message
news:0Z*******************@bignews1.bellsouth.net. ..
Hi all.
I can't find anything to explain how to prevent losing my object
reference.

I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data and
populate the document with a report, then open the document. It all works
great except the document opens and immediately closes.
What I don't understand is this:
If I Dim as New the document object in a function, then process the data
and report in the other class without threading, the document opens and
stays open even though the function is exited and the document object and
other class go out of scope.
But, if I do the same thing using threading, the document and class still
go out of scope, but now I lose the document completely.

Can anyone explain this? Better yet, how to avoid this? Or point me to a
reference?

So frustrating, so frustrating...

Thanks,
Tom

Jul 13 '06 #2
It's a generic document form with vb.net.

T

Samuel Shulman wrote:
>It Word document?
"tomb" <to**@technetcenter.comwrote in message
news:0Z*******************@bignews1.bellsouth.net ...

>>Hi all.
I can't find anything to explain how to prevent losing my object
reference.

I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data and
populate the document with a report, then open the document. It all works
great except the document opens and immediately closes.
What I don't understand is this:
If I Dim as New the document object in a function, then process the data
and report in the other class without threading, the document opens and
stays open even though the function is exited and the document object and
other class go out of scope.
But, if I do the same thing using threading, the document and class still
go out of scope, but now I lose the document completely.

Can anyone explain this? Better yet, how to avoid this? Or point me to a
reference?

So frustrating, so frustrating...

Thanks,
Tom


Jul 13 '06 #3

tomb wrote:
<snip>
I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data
and populate the document with a report, then open the document. It all
works great except the document opens and immediately closes.
<snip>

Since the form is created in another thread, as soon as the threaded
function finishes, the thread vanishes and the form 'dies'.

One possible solution would be to open the form with ShowDialog(), but
notice that this will show the form modally and may prevent your
function from working.

HTH,

Branco

Jul 13 '06 #4
Actually, the form is declared and instantiated in my non-threaded
function, then passed to the other class, that then is called in a
thread to do the processing. But I appreciate the attempt.

T

Branco Medeiros wrote:
>tomb wrote:
<snip>

>>I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data
and populate the document with a report, then open the document. It all
works great except the document opens and immediately closes.

<snip>

Since the form is created in another thread, as soon as the threaded
function finishes, the thread vanishes and the form 'dies'.

One possible solution would be to open the form with ShowDialog(), but
notice that this will show the form modally and may prevent your
function from working.

HTH,

Branco
Jul 13 '06 #5

tomb wrote:
Actually, the form is declared and instantiated in my non-threaded
function, then passed to the other class, that then is called in a
thread to do the processing. But I appreciate the attempt.
It would help if you posted some code, then... =)

Regards,

Branco.

Jul 13 '06 #6
You need to pass a reference to your document to your thread. Otherwise,
when the function that opens the document terminates, your document goes out
of scope and the GC reclaims it.

Mike Ober.

"tomb" <to**@technetcenter.comwrote in message
news:0Z*******************@bignews1.bellsouth.net. ..
Hi all.
I can't find anything to explain how to prevent losing my object
reference.
>
I have a function that instantiates a document object, passes it to
another class, then uses a thread for the other class to process data
and populate the document with a report, then open the document. It all
works great except the document opens and immediately closes.

What I don't understand is this:
If I Dim as New the document object in a function, then process the data
and report in the other class without threading, the document opens and
stays open even though the function is exited and the document object
and other class go out of scope.
But, if I do the same thing using threading, the document and class
still go out of scope, but now I lose the document completely.

Can anyone explain this? Better yet, how to avoid this? Or point me to
a reference?

So frustrating, so frustrating...

Thanks,
Tom


Jul 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
by: Elliot Rodriguez | last post by:
Hi: I am writing a WinForm app that contains a DataGrid control and a StatusBar control. My goal is to update the status bar using events from a separate class, as well as some other simple...
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
4
by: Chris Johnson | last post by:
Ill be the first to admit this is way beyond my current scope as a VB programmer but Im learning as I go. I playing with the new Threading features exposed by the 2.0 framework and have writting...
41
by: km | last post by:
Hi all, Is there any PEP to introduce true threading features into python's next version as in java? i mean without having GIL. when compared to other languages, python is fun to code but i feel...
4
by: Bryan | last post by:
Im new to threading and am experiencing some confusion as to how to correctly use AfxBeginThread in my singleton class. The code that I want to thread out is in a single function, Init(). Is...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
0
by: R K | last post by:
I am delevoping a Scheduler module whose functionality is to load the Scheduled Item Details every day (For this I have created a System.Threading.TimerCallBack with Timespan 1 day) in a stack. Once...
12
by: =?Utf-8?B?SmFyb2Q=?= | last post by:
Hi! I've done some code using threading just to check if writing code improperly can cause serious issues when using somehow safe data types. So in my understanding a stack ( collection type )...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...

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.