Topaz Filer - Email filing software
Can threads share objects?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.


John
Hi,

I have a worker thread that fills in data fields in a class. It takes
a few minutes to fill in all the fields because of slow database
queries.

I want to display the filled out fields in a GUI in the main thread.

I give the worker thread a queue full of the objects that I want
"filled out". When the worker fills out an object I use a callback to
let the main thread know that a particular object is ready to be
displayed.

The problem is that my main thread hangs when trying to read data out
of the object that was put there by the worker thread until the worker
thread stops being busy. Once it's done all it's work everything is
cool. But while it's still processing I can get at any of the data.

Does this make sense? What am I missing?

Thanks,
John
Reply to this message...
Vote that this is a GOOD answer...
 
New BootFX DBGet build available
Twitter and Snow… simple #uksnow
 
    
Eliyahu \(Vyacheslav\) Biktagirov
Strange.. I never got such problem. Anyway, why you trying
read object before it filled if you are using some kind of
synchronization?
Reply to this message...
Vote that this is a GOOD answer...
 
Windows 7 compatible tool for mounting ISO images
Introduction to BootFX’s Object Relational Mapping Functionality article now live on CodeProject
 
    
Vyas Bharghava
You have to synchronize on the object that's being filled & read for
display.
But if you're locking the whole object when you're filling it, the result
you're getting is right i.e, the GUI thread / the thread that displays data,
will get blocked till the worker thread releases it.
Rather, synchronize the methods and don't lock the whole class.

Vyas

"John" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Nick
I think you are getting many terms mixed up but this is what you are looking
for and it has worked for me.

class myClass () {
public myClass() {
Thread loadThread = new Thread(new ThreadStart(myMethod));
loadThread.Name = "Type Loader";
loadThread.IsBackground = true;
loadThread.Start();
}

private void myMethod () {
// do processing here
progressBar.Value++;
}
}

"Vyas Bharghava" <Click here to reveal e-mail address> wrote in message
news:e413bW57BHA.2256@tkmsftngp02...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Xenu Link Sleuth
Chromium OS – really?
 
    
John
I have been doing exactly what you show here. However, I don't use:

loadThread.IsBackground = true;

Could this be causing my problems? What happens if you don't set
IsBackground to true?

John

"Nick" <Click here to reveal e-mail address> wrote in message news:<OJLG#G67BHA.2288@tkmsftngp03>...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Invocation Software – the new name for the makers of Topaz Filer
Agile Modeling
 
 
System.Threading.Thread
System.Threading.ThreadStart




Ad
BootFX
Reliable and powerful .NET application framework.
Looking to invest in a major software project? Technical and commercial advice available here.
Other Helpful Sites
MBR 247
Topaz Filer
SharePoint Email Filing
Software Advisory Services
 
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734