Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Trouble with drawing on winfrom in new thread

Trouble with drawing on winfrom in new thread

Scheduled Pinned Locked Moved C#
graphicshelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frozzeg
    wrote on last edited by
    #1

    Thread th = new Thread(delegate() { e.Graphics.DrawEllipse(new Pen(Brushes.Aqua, 10), new Rectangle(20, 20, 20, 20)); //this line throw new exception "Invalid argument" }); th.Start(); help pls

    L T 2 Replies Last reply
    0
    • F Frozzeg

      Thread th = new Thread(delegate() { e.Graphics.DrawEllipse(new Pen(Brushes.Aqua, 10), new Rectangle(20, 20, 20, 20)); //this line throw new exception "Invalid argument" }); th.Start(); help pls

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I suggest you carefully read the following two little articles: http://www.perceler.com/articles1.php?art=animation1[^] http://www.perceler.com/articles1.php?art=crossthreads1[^] :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
      [The QA section does it automatically now, I hope we soon get it on regular forums as well]


      1 Reply Last reply
      0
      • F Frozzeg

        Thread th = new Thread(delegate() { e.Graphics.DrawEllipse(new Pen(Brushes.Aqua, 10), new Rectangle(20, 20, 20, 20)); //this line throw new exception "Invalid argument" }); th.Start(); help pls

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        First you are not passing the eventargs variable e into the delegate function. Secondly, you cannot perform GUI operations from any thread except for the one on which the form was created.

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        F 1 Reply Last reply
        0
        • T The Man from U N C L E

          First you are not passing the eventargs variable e into the delegate function. Secondly, you cannot perform GUI operations from any thread except for the one on which the form was created.

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          F Offline
          F Offline
          Frozzeg
          wrote on last edited by
          #4

          form1.CreateGraphics() and this is workling in other thread

          D 1 Reply Last reply
          0
          • F Frozzeg

            form1.CreateGraphics() and this is workling in other thread

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Just because you can do it doesn't mean it's a good idea. You're still going to run into issues somewhere down the line. You absolutely cannot do any drawing to the controls on a thread other than the one the control was created on.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups