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. Threading problem in C# [modified]

Threading problem in C# [modified]

Scheduled Pinned Locked Moved C#
csharpasp-netgraphicsdesignperformance
2 Posts 2 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.
  • M Offline
    M Offline
    mihai123
    wrote on last edited by
    #1

    Hello, I have a weird problem with my c# code. It works fine on my pc sempron 1600+ but it cracks on dual core processors. I have two classes (the main form, and one that implements some change to an image). I want to show the change in real time on the form on a picture box. So I created a thread and use delegates and beginInvoke method to refresh the pictureBox after I changed some pixels of the image that I display there. The application works fine on low speed processors but on dual core or processor with 2ghz+ it cracks, it put the processor on 100% and does not make any changes to the pictureBox. Also I putted some breakpoints and I was stupefied, the application enters the section that changed the pixels, enters the delegate function that refresh the panel but it doesn't make any changes... I have not clue what I done wrong. Note: I tried the Invoke method too but it the same problem. I'm open to any suggestions Thanks Edit add some code The delegates public delegate void DelegatePictureBoxUpdate(); public delegate void DelegatePictureBoxLoad(Bitmap image, int nr); public delegate void DelegateActualizareStatus(); public delegate void DelegateActualizareFinal(); Thread fir; // events used to stop worker thread ManualResetEvent m_EventStopThread; ManualResetEvent m_EventThreadStopped; // Delegate instances used to cal user interface functions // from worker thread: public DelegatePictureBoxUpdate m_DelegatePictureBoxUpdate; public DelegatePictureBoxLoad m_DelegatePictureBoxLoad; public DelegateActualizareStatus m_DelegateStatus; public DelegateActualizareFinal m_DelegateFinal; The delegate function that loads and refresh the pctBox public void LoadPictureBox(Bitmap final, int nr) { progressInpaint.Maximum=nr; progressInpaint.Step= nr/20; pctBoxReparat.Image=final; lblProprietati.Enabled=true; lblProprietati.Text+=":"+nr.ToString(); } public void UpdateStatus() { progressInpaint.Value+=progressInpaint.Step; progressInpaint.Refresh(); } //the form close event void MainFormFormClosed(object sender, FormClosedEventArgs e) { if ( fir!= null && fir.IsAlive ) // thread is active { // set event "Stop" m_EventStopThread.Set(); // wait when thread will stop or finish while (fir.IsAlive) { // We cannot use here infi

    Z 1 Reply Last reply
    0
    • M mihai123

      Hello, I have a weird problem with my c# code. It works fine on my pc sempron 1600+ but it cracks on dual core processors. I have two classes (the main form, and one that implements some change to an image). I want to show the change in real time on the form on a picture box. So I created a thread and use delegates and beginInvoke method to refresh the pictureBox after I changed some pixels of the image that I display there. The application works fine on low speed processors but on dual core or processor with 2ghz+ it cracks, it put the processor on 100% and does not make any changes to the pictureBox. Also I putted some breakpoints and I was stupefied, the application enters the section that changed the pixels, enters the delegate function that refresh the panel but it doesn't make any changes... I have not clue what I done wrong. Note: I tried the Invoke method too but it the same problem. I'm open to any suggestions Thanks Edit add some code The delegates public delegate void DelegatePictureBoxUpdate(); public delegate void DelegatePictureBoxLoad(Bitmap image, int nr); public delegate void DelegateActualizareStatus(); public delegate void DelegateActualizareFinal(); Thread fir; // events used to stop worker thread ManualResetEvent m_EventStopThread; ManualResetEvent m_EventThreadStopped; // Delegate instances used to cal user interface functions // from worker thread: public DelegatePictureBoxUpdate m_DelegatePictureBoxUpdate; public DelegatePictureBoxLoad m_DelegatePictureBoxLoad; public DelegateActualizareStatus m_DelegateStatus; public DelegateActualizareFinal m_DelegateFinal; The delegate function that loads and refresh the pctBox public void LoadPictureBox(Bitmap final, int nr) { progressInpaint.Maximum=nr; progressInpaint.Step= nr/20; pctBoxReparat.Image=final; lblProprietati.Enabled=true; lblProprietati.Text+=":"+nr.ToString(); } public void UpdateStatus() { progressInpaint.Value+=progressInpaint.Step; progressInpaint.Refresh(); } //the form close event void MainFormFormClosed(object sender, FormClosedEventArgs e) { if ( fir!= null && fir.IsAlive ) // thread is active { // set event "Stop" m_EventStopThread.Set(); // wait when thread will stop or finish while (fir.IsAlive) { // We cannot use here infi

      Z Offline
      Z Offline
      Zoltan Balazs
      wrote on last edited by
      #2

      Using some breakpoints to debug threading issues is not the best idea. If you could demonstrate what you have done maybe we can help you.

      Work @ Network integrated solutions | Flickr | A practical use of the MVC pattern

      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