Coffeehouse Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

another dumb question..

Back to Forum: Coffeehouse
  • User profile image
    antisocial

    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.

  • User profile image
    antisocial

    oh and this is in C#

  • User profile image
    cbae

    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.

  • User profile image
    magicalclick

    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.

     

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    blowdart

    , 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)

     

  • User profile image
    evildictait​or

    , 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) Smiley

  • User profile image
    Minh

    can you provide code samples?

  • User profile image
    blowdart

    , 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) Smiley

    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.

     

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.