Announcement

Collapse
No announcement yet.

Passing an Object to a PowerThread

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing an Object to a PowerThread

    I am having difficulty passing an object to a PowerThread object.

    I wish to raed a file and keep the contents after being parsed in an object.

    I create the ThreadParam object OK

    I pass the object I want to store the data in OK

    When I execute the thread however I get the following:

    Exception: Memory Access Violation


    If I create the object to store the data within the thread itself it is OK, but then I cant use the object with another thread.

    Has anyone tried passing objects to PowerThread with success.

    I am creating an object for the threadparam parameters and passing it OK.

    The issue I have is with an object which is one of the properties of the object I pass as a prameter. The object itself has a property which contains a powercollection.

    Cant post the code as restricted.

    If anyone can suggest based on what I have said that would be good.

    If not I will strip out a baseline sample and post that.



    Can anyone help.

    Kind regards,
    Neil
    Kind regards,
    Neil

    http://www.BASICProgramming.info

  • #2
    As PB initializes the COM library using single-thread apartment, you may need to

    1. Call CoUninitialize
    2. Call CoInitializeEx(NULL, &H0)

    at the beginning of the program. &H0 is the value of the COINIT_MULTITHREADED constant.

    See: https://docs.microsoft.com/en-us/win...coinitializeex
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Thanks for the suggestion.

      I will look into giving that a go at the weekend. As I will probably have to resort to Thread Create instead of PowerThread for that.

      As the documentation suggests that the threading can only be set once this may be a problem using objects.

      I do not know if the constructor would work in a PowerThread and secondly PB may have already set the threading before that.


      Just to put the icing on the cake for me, I have created a test app. Which works. (?!?!?)

      So I will try putting the real code back a bit at a time.

      My code is dying on the launch of a PowerThread. Compiled it just dumps the app. Via debug I get the violation msg.

      I will attach my testbed here just in case someone can suggest what I am doing wrong. (but the test works so ...mmm)



      Well I was going to upload it but I cant upload the .PBrj project file or the res file. the forum wont let me.
      The rest is there though.


      Attached Files
      Kind regards,
      Neil

      http://www.BASICProgramming.info

      Comment


      • #4
        Originally posted by Neil Prichard View Post
        Well I was going to upload it but I cant upload the .PBrj project file or the res file. the forum wont let me.
        The rest is there though.
        Why not upload a zip containing all the necessary files, that's the way most people do it if they have multiple files

        Comment


        • #5
          Compelete Zip with all files.

          Thanks Stuart

          Attached Files
          Kind regards,
          Neil

          http://www.BASICProgramming.info

          Comment

          Working...
          X