-
May 14th, 2014, 10:00 AM
#1
Graphic User Interface freezes after 2 mins
Good day to all,
Please i need your support on how to solve this Problem.I developed a graphic user Interface with 37 trackbars.the trackbars are used to control Led brightness.The application works very well except that after 2mins it hangs.So i have to re-load it before it can be used again.The lines of code below is for two of the 37 trackbar.
Code:
private Timer _scrollingTimer = null;
private void trackBar1_Scroll(object sender, EventArgs e)
{
if (_scrollingTimer == null)
{
// Will tick every 500ms (change as required)
_scrollingTimer = new Timer()
{
Enabled = false,
Interval = 500,
Tag = (sender as TrackBar).Value
};
_scrollingTimer.Tick += (s, ea) =>
{
// check to see if the value has changed since we last ticked
if (trackBar1.Value == (int)_scrollingTimer.Tag)
{
// scrolling has stopped so we are good to go ahead and do stuff
_scrollingTimer.Stop();
myFtdiDevice.write(dataTowrite,dataTowrite.Length,ref numByteswritten);
int percent =(int )(((double)trackbar1.Value/(double)reackbar1.Maximum) * 100);
label2.Text = (percent.ToString()) + "%";
data[0] = Convert.ToByte(percent);
data[1] = 0x6A;
myFtdiDevice.write(data,2,ref numByteswritten);
_scrollingTimer.Dispose();
_scrollingTimer = null;
}
else
{
// record the last value seen
_scrollingTimer.Tag = trackBar1.Value;
}
};
_scrollingTimer.Start();
}
}
private void trackBar2_Scroll(object sender, EventArgs e)
{
if (_scrollingTimer == null)
{
// Will tick every 500ms (change as required)
_scrollingTimer = new Timer()
{
Enabled = false,
Interval = 500,
Tag = (sender as TrackBar).Value
};
_scrollingTimer.Tick += (s, ea) =>
{
// check to see if the value has changed since we last ticked
if (trackBar2.Value == (int)_scrollingTimer.Tag)
{
// scrolling has stopped so we are good to go ahead and do stuff
_scrollingTimer.Stop();
myFtdiDevice.write(dataTowrite,dataTowrite.Length,ref numByteswritten);
int percent =(int )(((double)trackbar2.Value/(double)reackbar2.Maximum) * 100);
label3.Text = (percent.ToString()) + "%";
data[0] = Convert.ToByte(percent);
data[1] = 0x6A;
myFtdiDevice.write(data,2,ref numByteswritten);
_scrollingTimer.Dispose();
_scrollingTimer = null;
}
else
{
// record the last value seen
_scrollingTimer.Tag = trackBar2.Value;
}
};
_scrollingTimer.Start();
}
}
Is there any way i can adjust these code in order to prevent freezing.Thank you all for the usual Support.Best regards.
Firstoption.
-
May 14th, 2014, 01:17 PM
#2
Re: Graphic User Interface freezes after 2 mins
Is myFtdiDevice blocking or operating in a different thread (from the UI thread)?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|