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