Threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredje

    #1

    Threading

    Hello,

    I have the following problem:
    I'm making a application that add at runtime usercontrols.
    Each usercontrol have a function that converts a image.
    This conversion takes a while and at the time the function is running the
    applications blocks.
    So I want to implement Threading but only for the moment this function is
    running.
    I have to pass arguments to the function like width, height,...

    How can I prevent that the application doesn't block when this function is
    running?

    Thanks in advance.


  • Drebin

    #2
    Re: Threading

    You answered your own question: by starting a thread..

    You can't send ThreadStart any arguments, so what most people do - is create
    a class, that will do the thread work.. so in psuedo-code:

    -create an instance of the threadworker class (call it objWorker)
    -assign height, width, other properties to objWorker
    -create a thread, and assign it to objWorker.DoWor k()

    hth

    "Fredje" <codaria@hotmai l.com> wrote in message
    news:Gk33b.8957 6$F92.9675@afro dite.telenet-ops.be...[color=blue]
    > Hello,
    >
    > I have the following problem:
    > I'm making a application that add at runtime usercontrols.
    > Each usercontrol have a function that converts a image.
    > This conversion takes a while and at the time the function is running the
    > applications blocks.
    > So I want to implement Threading but only for the moment this function is
    > running.
    > I have to pass arguments to the function like width, height,...
    >
    > How can I prevent that the application doesn't block when this function is
    > running?
    >
    > Thanks in advance.
    >
    >[/color]


    Comment

    • AlexS

      #3
      Re: Threading

      You can pass back created picture or controls to UI thread. Just remember,
      that you can't update UI thread controls (main form) reliably from another
      thread. Take a look at InvokeRequired and Invoke/BeginInvoke methods of
      Control object.

      HTH
      Alex

      "Fredje" <codaria@hotmai l.com> wrote in message
      news:qm43b.1742 $Md5.140425@pho bos.telenet-ops.be...[color=blue]
      > Thank you very much.
      >
      > This already working.
      > The result of the function is a picture. This picture must be placed in a
      > picturebox in the parent of the class objWorker. I've solved this now by
      > passing the picturebox form the parent width the constructor of the object
      > objWorker.
      > Is this a good way of working?
      >
      > I want also when the function is completed width running the tread stops[/color]
      and[color=blue]
      > dipose.
      > But before the tread dipose the image must be saved.
      > Is it better that is do this from the object objWorker or from the parent?
      >
      > Thank you again
      >
      > "Drebin" <tRhEeMdOrVeEbi n@hotmail.com> wrote in message
      > news:Nn33b.3460 2$Vx2.15019914@ newssvr28.news. prodigy.com...[color=green]
      > > You answered your own question: by starting a thread..
      > >
      > > You can't send ThreadStart any arguments, so what most people do - is[/color]
      > create[color=green]
      > > a class, that will do the thread work.. so in psuedo-code:
      > >
      > > -create an instance of the threadworker class (call it objWorker)
      > > -assign height, width, other properties to objWorker
      > > -create a thread, and assign it to objWorker.DoWor k()
      > >
      > > hth
      > >
      > > "Fredje" <codaria@hotmai l.com> wrote in message
      > > news:Gk33b.8957 6$F92.9675@afro dite.telenet-ops.be...[color=darkred]
      > > > Hello,
      > > >
      > > > I have the following problem:
      > > > I'm making a application that add at runtime usercontrols.
      > > > Each usercontrol have a function that converts a image.
      > > > This conversion takes a while and at the time the function is running[/color][/color]
      > the[color=green][color=darkred]
      > > > applications blocks.
      > > > So I want to implement Threading but only for the moment this function[/color][/color]
      > is[color=green][color=darkred]
      > > > running.
      > > > I have to pass arguments to the function like width, height,...
      > > >
      > > > How can I prevent that the application doesn't block when this[/color][/color][/color]
      function[color=blue]
      > is[color=green][color=darkred]
      > > > running?
      > > >
      > > > Thanks in advance.
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...