473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Gui stopped responding after two updates

2
Good day to all,
Please i need your help and support on how to resolve this problem.My UI thread stopped responding after two updates.In an attempt to solve this problem,i had tried to use Backgroundorker and Asynchronouse programming.With the backgroundwork,my GUI did not respond.Values sent to the GUI did not even show at all,so there was nothing like
updates when i used backgroundworker.However when i used Asynchronouse programming,the value sent to the GUI was displayed and it was updated twice(for example,if the value sent to the GUI is 10,this value(10)will be displayed and then updated to 12).The values sent to the GUI comes from the return value of the function below.

Expand|Select|Wrap|Line Numbers
  1.   ftStatus = myFtdiDevice.Read(readData, numBytesToRead, ref numBytesRead);
  2.            value = Convert.ToString(readData[0]);
  3.            return value;
  4.  
This function reads value from the SerialPort at intervals which is determine by the Timer.I have on my form 4 buttons,one richtextbox with a label and one checkbox.The first two buttons connects my GUI to the SerialPort while the remaining two buttons are used to ON/OFF Leds.The Checkbox is used to receive data from the SerialPort whenever it is checked.One more observation with the Asynchronouse code is that,i can still move the GUI form around whenever it stops updating, however,if i click any of the four buttons afterward,then the whole of the form freezes.

Below are my program codes for the Backgroundworker and Asynchronouse respectively.



BACKGROUNDWORKER CODE
Expand|Select|Wrap|Line Numbers
  1.   private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2.         {
  3.             if (this.checkBox1.Checked && !this.backgroundWorker1.IsBusy)
  4.             {
  5.                 this.backgroundWorker1.RunWorkerAsync();
  6.             }
  7.             else if (!this.checkBox1.Checked && this.backgroundWorker1.IsBusy)
  8.             {
  9.                 this.backgroundWorker1.CancelAsync();
  10.             }
  11.         }
  12.         private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  13.         {
  14.             UInt32 numBytesRead = 0;
  15.             UInt32 numBytesToRead = 1;
  16.             byte[] readData = new byte[10];
  17.  
  18.  
  19.             while (!this.backgroundWorker1.CancellationPending)
  20.             {
  21.                 // Do some work.
  22.                 Thread.Sleep(1000);
  23.                 ftStatus = myFtdiDevice.Read(readData, numBytesToRead, ref numBytesRead);
  24.                 // Update the UI.
  25.                 this.backgroundWorker1.ReportProgress(0, readData[0].ToString());
  26.  
  27.             }
  28.         }
  29.  
  30.         private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
  31.         {
  32.             label11.Text = (string)e.UserState + "ºC";
  33.  
  34.         }                         
  35.  
ASYNCHRONOUSE CODE

Expand|Select|Wrap|Line Numbers
  1. private  void rxtemp_CheckedChanged(object sender, EventArgs e)
  2.        {
  3.  
  4.            aTimer = new System.Timers.Timer(1000);
  5.            aTimer.Elapsed += new ElapsedEventHandler(DisplayTempValue);
  6.            aTimer.AutoReset = true;
  7.            aTimer.Enabled = true;
  8.  
  9.        }
  10.  
  11.        private string HeavyOperation()
  12.        {
  13.            UInt32 numBytesRead = 0;
  14.            UInt32 numBytesToRead = 1;
  15.            byte[] readData = new byte[255];
  16.            string value;
  17.            ftStatus = myFtdiDevice.Read(readData, numBytesToRead, ref numBytesRead);
  18.            value = Convert.ToString(readData[0]);
  19.            return value;
  20.        }
  21.  
  22.        private Task<string> HeavyOperationAsync()
  23.        {
  24.            return Task.Run<string>(() => HeavyOperation());
  25.  
  26.        }
  27.        private async void DisplayTempValue(object source, ElapsedEventArgs e)
  28.        {
  29.            string result = await HeavyOperationAsync();
  30.            label3.Invoke(new Action(() =>
  31.            {
  32.                label3.Text = result + "ºC";
  33.  
  34.            }));
  35.        }
  36.  
  37.  
I would be very glad if somebody could put me through on how to resolve this Problem. i have no idea of what is going on behind the Scene.Your advice and Suggestion will be highly appreciated.Thank you for the usual Support.

Best regards.
Nov 12 '14 #1
0 1103

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stephen Goldschmidt | last post by:
Hello, A few days ago my asp pages on my web server running IIS 5.0 stop responding. I can view any html pages but not pages ending with asp. can anyone help me with this. Tbank you
0
by: Michael Bourgon | last post by:
I've been having the same problem for 2 weeks now. If anyone has any ideas, I'd love to hear them. We are using both SQL and Windows Authentication. I was running a Profiler Trace at the time,...
20
by: JulioHM | last post by:
Hello, Not sure if this is the right discussion group to post this, but here it goes. For some god-forsaken reason (which I can't find out either) MSIE stopped executing any JavaScripts. In...
2
by: Nils Hedström | last post by:
Today my stateserver (running at the same computer at the web-server) suddenly stopped responding (after 10 days working perfectly). I did not see any entry in the eventlog indicating that the...
1
by: Mike | last post by:
I have an application that was developed in VB.NET. Its been in production since October without any problems and that was the last time anyone touched any of the code. Today I got a call from a...
22
by: Brett | last post by:
I have a second thread, t2, that errors out and will stop. It's status is then "Stopped". I try to start t2 from thread 1, t1, by checking If t2.threadstate = "Stopped" Then t2.start() ...
1
by: ttpiper | last post by:
I have a Compaq Presario SR2170NX runing Vista (arrrrrg!). If I put a music CD into the DVD/CD drive, it will spin up and read the song titles but it will not play any tunes. The tunes that came...
1
by: =?Utf-8?B?bmVpbG9scw==?= | last post by:
Everytime I reboot my computer I get a baloon pop up that says Automatic Updates is turned off. When I try to manualy update Windows I get the following message from Internet Explorer. Automatic...
7
by: mills.toby | last post by:
We have a Windows 2003 Server, serving an asp.net (2.0) website. Recently the website stopped responding. When trying to access the website, no response is received at all. This includes when...
1
by: Eric berg | last post by:
I have a very tricky problem with my primary laptops keyboard. For some unknown reason the keyboard has stopped responding under windows. I can login to my windows machine but afterwords (For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.