ok the book im reading dont explain this so.... i have to ask when u create an object be it a structure or a class. and then you RETURN from it. does it go bye bye never to be seen again. or is it still there and you can get at the variables that are in there? or am i just totally off in nvr nvr land.
-
-
oh and this is in C#
-
If the only reference to the object is a local variable within the method, then the object goes away once code execution returns from the method. If you need to reference the object elsewhere, assign it to a member of the class.
-
In C# it is automatically managed, so, you don't care about it. Just remember that if you keep it somewhere, you can get it. As long as you know how to get it, the data will be there for you to get it. If you don't keep it somewhere, then, eventually the cleaning lady will throw it away.
-
10 hours ago, magicalclick wrote
In C# it is automatically managed, so, you don't care about it. Just remember that if you keep it somewhere, you can get it. As long as you know how to get it, the data will be there for you to get it. If you don't keep it somewhere, then, eventually the cleaning lady will throw it away.
Mostly.
If you have an object that supports IDisposable you can still pass it around once it's been disposed, but operations on it will likely error (as I found out when I was a dumb * and passed System.Web.Request into a background thread)
-
1 hour ago, blowdart wrote
as I found out when I was a dumb * and passed System.Web.Request into a background thread
System.Web.Requests are already in background worker threads :/
And your idea will work, so long as you block the thread you got it from so it doesn't Dispose it (but that kind of destroys the point of pushing it to a background thread)

-
can you provide code samples?
-
1 hour ago, evildictaitor wrote
*snip*
System.Web.Requests are already in background worker threads :/
And your idea will work, so long as you block the thread you got it from so it doesn't Dispose it (but that kind of destroys the point of pushing it to a background thread)

Well I was kicking off the background processing in a controller action, via Task =>. It worked, until under stress timing issues kicked in and the darned request was disposed by the time some threads wanted it. Arf.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.