How to deal with this thread?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QW5kcmV3?=

    How to deal with this thread?

    Hello, friends,

    In my app, after a user selects a document, I create a new thread to print
    this document so that this user may continue to do his/her work.

    Thread thread = new Thread(new
    ThreadStart(bul kPrint.bulkPrin t));
    thread.SetApart mentState(Apart mentState.STA);
    thread.IsBackgr ound = true;
    thread.Start();

    I currently leave this thread like this without explicitly terminate it.

    I don't feel right since I think it should be terminated somehow.

    What should I do and how? Thanks a lot!
  • Jon Skeet [C# MVP]

    #2
    Re: How to deal with this thread?

    Andrew <Andrew@discuss ions.microsoft. comwrote:
    In my app, after a user selects a document, I create a new thread to print
    this document so that this user may continue to do his/her work.
    >
    Thread thread = new Thread(new
    ThreadStart(bul kPrint.bulkPrin t));
    thread.SetApart mentState(Apart mentState.STA);
    thread.IsBackgr ound = true;
    thread.Start();
    >
    I currently leave this thread like this without explicitly terminate it.
    >
    I don't feel right since I think it should be terminated somehow.
    >
    What should I do and how? Thanks a lot!
    Why do you feel you need to terminate it? If it finishes on its own, it
    will go away. If there are only background threads left in the process,
    the process will die.

    Why do you want to kill it?

    --
    Jon Skeet - <skeet@pobox.co m>
    Web site: http://www.pobox.com/~skeet
    Blog: http://www.msmvps.com/jon_skeet
    C# in Depth: http://csharpindepth.com

    Comment

    • =?Utf-8?B?QW5kcmV3?=

      #3
      Re: How to deal with this thread?

      If this thread can go away by itself, that is great.

      One reason I think it should be explicitely terminated is that I got the
      following message which I have never had before creating this thread:

      COM object that has been separated from its underlying RCW cannot be used"
      exception within threads

      "Jon Skeet [C# MVP]" wrote:
      Andrew <Andrew@discuss ions.microsoft. comwrote:
      In my app, after a user selects a document, I create a new thread to print
      this document so that this user may continue to do his/her work.

      Thread thread = new Thread(new
      ThreadStart(bul kPrint.bulkPrin t));
      thread.SetApart mentState(Apart mentState.STA);
      thread.IsBackgr ound = true;
      thread.Start();

      I currently leave this thread like this without explicitly terminate it.

      I don't feel right since I think it should be terminated somehow.

      What should I do and how? Thanks a lot!
      >
      Why do you feel you need to terminate it? If it finishes on its own, it
      will go away. If there are only background threads left in the process,
      the process will die.
      >
      Why do you want to kill it?
      >
      --
      Jon Skeet - <skeet@pobox.co m>
      Web site: http://www.pobox.com/~skeet
      Blog: http://www.msmvps.com/jon_skeet
      C# in Depth: http://csharpindepth.com
      >

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: How to deal with this thread?

        Andrew <Andrew@discuss ions.microsoft. comwrote:
        If this thread can go away by itself, that is great.
        >
        One reason I think it should be explicitely terminated is that I got the
        following message which I have never had before creating this thread:
        >
        COM object that has been separated from its underlying RCW cannot be used"
        exception within threads
        That sounds like it's to do with what you're doing *on* the thread -
        which would depend on what "bulkPrint" is. Unfortunately I'm not
        terribly hot on COM...

        --
        Jon Skeet - <skeet@pobox.co m>
        Web site: http://www.pobox.com/~skeet
        Blog: http://www.msmvps.com/jon_skeet
        C# in Depth: http://csharpindepth.com

        Comment

        • Peter Duniho

          #5
          Re: How to deal with this thread?

          On Thu, 10 Jul 2008 14:12:08 -0700, Andrew
          <Andrew@discuss ions.microsoft. comwrote:
          If this thread can go away by itself, that is great.
          >
          One reason I think it should be explicitely terminated is that I got the
          following message which I have never had before creating this thread:
          >
          COM object that has been separated from its underlying RCW cannot be
          used"
          exception within threads
          I haven't seen that exception before. But it suggests that there's
          something about your code other than simply creating a new thread. I
          assume here RCW means "runtime callable wrapper", which is the bridge
          between managed code and COM objects. I admit, I don't know how a COM
          object would get "separated from its RCW", but whatever's going on, it's
          not because you're not terminating the thread explicitly.

          If you can post a concise-but-complete code sample that demonstrates how
          and why you get that exception, and/or can post the _exact_ text
          associated with the exception, someone might be able to help with the
          problem you're actually having.

          Pete

          Comment

          • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

            #6
            Re: How to deal with this thread?

            From reading around online. It looks like this might be caused by you not
            releasing your COM object properly by Disposing them. Check that you have
            correctly released any objects and explicitly called Dispose on the COM
            objects/wrappers you are using before the thread finishes.

            --
            Ciaran O''Donnell
            try{ Life(); } catch (TooDifficultException) { throw Toys(); }



            "Andrew" wrote:
            If this thread can go away by itself, that is great.
            >
            One reason I think it should be explicitely terminated is that I got the
            following message which I have never had before creating this thread:
            >
            COM object that has been separated from its underlying RCW cannot be used"
            exception within threads
            >
            "Jon Skeet [C# MVP]" wrote:
            >
            Andrew <Andrew@discuss ions.microsoft. comwrote:
            In my app, after a user selects a document, I create a new thread to print
            this document so that this user may continue to do his/her work.
            >
            Thread thread = new Thread(new
            ThreadStart(bul kPrint.bulkPrin t));
            thread.SetApart mentState(Apart mentState.STA);
            thread.IsBackgr ound = true;
            thread.Start();
            >
            I currently leave this thread like this without explicitly terminate it.
            >
            I don't feel right since I think it should be terminated somehow.
            >
            What should I do and how? Thanks a lot!
            Why do you feel you need to terminate it? If it finishes on its own, it
            will go away. If there are only background threads left in the process,
            the process will die.

            Why do you want to kill it?

            --
            Jon Skeet - <skeet@pobox.co m>
            Web site: http://www.pobox.com/~skeet
            Blog: http://www.msmvps.com/jon_skeet
            C# in Depth: http://csharpindepth.com

            Comment

            Working...