News
: SMF - Just Installed!
Home
Help
Search
Login
Register
Welcome,
Guest
. Please
login
or
register
.
February 08, 2012, 06:33:27 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
OmniThreadLibrary forum
>
OmniThreadLibrary
>
General Discussions
>
When to destroy object created in thread, and passed to main thread in message?
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: When to destroy object created in thread, and passed to main thread in message? (Read 666 times)
Vegar
Newbie
Posts: 23
When to destroy object created in thread, and passed to main thread in message?
«
on:
August 31, 2010, 08:17:03 AM »
Hi,
In my worker, I do a soap request, resulting in a newly created object holding data return from the request. This data is passed in a message to the main thread, which updates the gui with the data.
In the workers cleanup-method, I free the created object.
This results in a exception, cause the main thread has not always processed the message before the workers cleanup method gets called.
So where should I do the cleanup? Should I let the main thread destroy the object, or can I do anything to ensure that messages is processed before cleanup is called?
regards,
-Vegar
Logged
Primoz Gabrijelcic
Administrator
Hero Member
Posts: 520
Re: When to destroy object created in thread, and passed to main thread in message?
«
Reply #1 on:
August 31, 2010, 11:47:17 AM »
Free the object in the main thread. I do it all the time.
Passing ownership together with the data is useful semantics. You just have to keep in mind that you're doing it.
Logged
bendeguzz
Newbie
Posts: 8
Re: When to destroy object created in thread, and passed to main thread in message?
«
Reply #2 on:
September 06, 2010, 10:00:37 AM »
I needed something similar, and what I did was that I wrote a 'CleanUp()' procedure, which was called via a message from the main thread, after I've done everything I needed with the object.
PS: my object had a 'Processed' boolean field, which marked if it is freeable.
Logged
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
OmniThreadLibrary
-----------------------------
=> Announcements
=> General Discussions
Loading...