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. Thread Issues c# 2.0

Thread Issues c# 2.0

Scheduled Pinned Locked Moved C#
csharpvisual-studiodesigntutorialquestion
5 Posts 3 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.
  • T Offline
    T Offline
    Trance Junkie
    wrote on last edited by
    #1

    Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance

    W S 2 Replies Last reply
    0
    • T Trance Junkie

      Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance

      W Offline
      W Offline
      wheelerbarry
      wrote on last edited by
      #2

      Trance Junkie wrote:

      Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0

      What do u mean? throws an exception, hangs? From what i know, you should never use a non UI thread to update the UI, it causes it to deadlock.

      T 1 Reply Last reply
      0
      • T Trance Junkie

        Hi, Using csharp and the .net farmework i could run a thread like this and update the UI such as a label. example : Thread mythread = new Thread(new Threadstart(myfunction)); mythread.Start(); void myfunction() { lblstatus.text = DoWork(); } Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0 Why ?? :( Im using c# expression edition . Thanks in advance

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        It's not safe to access UI controls from threads other than the one they were created on. It mostly results in a freezing UI or other strange things. You're lucky nothing of this happened in your case. As there are many other people like you who weren't aware of this problem and accessed UI controls from other threads, it's no longer allowed. Use Invoke or BeginInvoke to update your label. This article[^] should help you.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        T 1 Reply Last reply
        0
        • W wheelerbarry

          Trance Junkie wrote:

          Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0

          What do u mean? throws an exception, hangs? From what i know, you should never use a non UI thread to update the UI, it causes it to deadlock.

          T Offline
          T Offline
          Trance Junkie
          wrote on last edited by
          #4

          Hi thanks for the speedy reply :-) No, it does not even get an exception, nothing of that sort and it does not even hang. emmm this is very strange.... :confused:

          1 Reply Last reply
          0
          • S Stefan Troschuetz

            It's not safe to access UI controls from threads other than the one they were created on. It mostly results in a freezing UI or other strange things. You're lucky nothing of this happened in your case. As there are many other people like you who weren't aware of this problem and accessed UI controls from other threads, it's no longer allowed. Use Invoke or BeginInvoke to update your label. This article[^] should help you.


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

            T Offline
            T Offline
            Trance Junkie
            wrote on last edited by
            #5

            Thank you Stefan i`ll check out the article. :rose:

            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