How to fire Text.TextChanged event with timer - c#

I do some validations regarding a path (if a file exists or not in the specified directory) and I need to fire up the TextChangedEvent after some time passed after the error to check again for that file.
Here is the code that I use to check for this error:
private void textBoxNovoSvrc_TextChanged(object sender, EventArgs e)
{
First++;
bool ok = false;
int same = 0;
try
{
if (!String.IsNullOrWhiteSpace(textBoxNovoSvrc.Text) && Program.Funcoes.ExisteDirectoria(textBoxNovoSvrc.Text) == true)
{
if (Erro2 == -1 || Erro2 == 0)
same = TextBoxSame(First);
if (same == 1)
return;
if (Global.VersaoInvalidaCli == true && Global.VersaoInvalidaSvrc == true)
{
Global.SvrcChanged = true;
buttonContinuar.PerformClick();
}
if (Program.Funcoes.ExisteFicheiro(textBoxNovoSvrc.Text + #"\OrcaService.exe.config") == true)
{
if (Global.VersaoInvalidaCli == true && Global.VersaoInvalidaSvrc == true)
{
buttonContinuar.PerformClick();
epDoesntExist1.Dispose();
epInvalidVersionSvrc.SetError(textBoxNovoSvrc, "Versão de Update Inválida!");
epInvalidVersionSvrc.Dispose();
epInvalidVersionCli.Dispose();
textBoxNovoCli.Text = Directory.GetParent(textBoxNovoSvrc.Text) + #"\Orca";
return;
}
if (textBox1 == textBoxNovoSvrc.Name || textBox2 == textBoxNovoSvrc.Name)
{
TextBoxes(textBox1, textBox2, true);
}
//Colocar aqui a versão mais recente do update;
string path = Directory.GetParent(textBoxNovoSvrc.Text).ToString();
//string Nome = System.IO.Path.GetFileName(path);
labelNovaVersãoServ.Text = Program.Funcoes.NovaVersao(path, Global.versionError);
Erro2 = 0;
ok = true;
errorProviderNoSvrc.Dispose();
epInvalidVersionSvrc.Dispose();
epDoesntExist2.Dispose();
Global.NovoServiço = textBoxNovoSvrc.Text;
textBoxNovoSvrc.BackColor = System.Drawing.Color.Green;
Continue++;
if (Continue >= 4)
buttonContinuar.Enabled = true;
else
{
buttonContinuar.Enabled = false;
}
btnBrowse2.Enabled = true;
textBoxNovoCli.Enabled = true;
textBoxNovoCli.Text = "";
textBoxNovoCli.Text = Directory.GetParent(textBoxNovoSvrc.Text).ToString() + #"\Orca";
}
else
{
ok = false;
textBoxNovoSvrc.BackColor = System.Drawing.Color.Red;
buttonContinuar.Enabled = false;
Erro2 = 1;
textBoxNovoSvrc.Focus();
epDoesntExist2.Dispose();
epInvalidVersionSvrc.Dispose();
errorProviderNoSvrc.SetError(textBoxNovoSvrc, "Ficheiro \"OrcaService.exe.config\" não existe na directoria");
return;
}
On the last else after errorProviderNoSvrc.SetError(textBoxNovoSvrc, "Ficheiro \"OrcaService.exe.config\" não existe na directoria");I need to fire a timer to wait around 5 seconds before firing up the textChanged event again.
Is this possible to do or do I need to take another aproach such as firing up a message box asking to check again for the file and firing up the TextChanged event "manually" by storing the path on a var and than chaging the text of the textbox like this TexBoxNovoSvrc.Text = "" and than TextBoxNovoSvrc.Text = OldPath.

You can use a timer:
at the begining(outside textBoxNovoSvrc_TextChanged), maybe in constructor
Timer t = new Timer();
t.Interval = 5000;
t.Tick += textBoxNovoSvrc_TextChanged;
Just before the last return
t.Start();
And at the start of textBoxNovoSvrc_TextChanged:
if(t.Enabled){
t.Stop()
}

Related

Multi threading hangs UI?

I am using multi threading to make tasks goes faster and smooth, when results increase into richtextbox the UI start hanging don't know why, I creating a webbrowser in thread and doing some other stuff in a single thread kind !
Using Thread as STA ( Single thread kind )
here is a snippet of the code !
foreach (string line in URLLMemoRichTxt.Lines)
{
string href = line;
if (href.Trim() != string.Empty)
{
//XtraMessageBox.Show(href);
if (StopGettingInnerLink == true)
{
AddLog("Getting links has been stopped successfully!");
StopGettingInnerLink = true;
break;
}
else if (StopGettingInnerLink == false)
{
AddLog("Getting links from " + href);
runBrowserThread( new Uri(href));
await Task.Delay(5000);
AddLog("Giving the tool some rest for 5 seconds ! ");
}
}
}
private void runBrowserThread(Uri url)
{
browserth = new Thread(() => {
var br = new WebBrowser();
br.ScriptErrorsSuppressed = true;
br.DocumentCompleted += browser_DocumentCompleted;
br.Navigate(url);
Application.Run();
});
browserth.SetApartmentState(ApartmentState.STA);
browserth.Start();
}
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var br = sender as WebBrowser;
string currentURL = br.Url.ToString();
if (br.Url == e.Url)
{
HtmlElementCollection acollection = br.Document.GetElementsByTagName("a");
foreach (HtmlElement a in acollection)
{
string href = a.GetAttribute("href");
if (URLLMemoRichTxt.InvokeRequired)
{
URLLMemoRichTxt.Invoke((MethodInvoker)delegate ()
{
if (!URLList.Contains(href) && href.Trim() != string.Empty && !href.Contains(".jpg") && !href.Contains(".png") && !href.Contains(".gif") && !href.Contains(".jpeg"))
{
URLList.Add(href);
// URLListView.Items.Add(href);
// adding new link ino listview !
// URLListCountLBL.Text = URLListView.Items.Count.ToString();
URLLMemoRichTxt.Text += href + "\n";
URLListCountLBL.Text = URLLMemoRichTxt.Lines.Length.ToString();
// runbrowserinthread(href);
}
});
}
else
{
if (!URLList.Contains(href) && href.Trim() != string.Empty && !href.Contains(".jpg") && !href.Contains(".png") && !href.Contains(".gif") && !href.Contains(".jpeg"))
{
URLList.Add(href);
// URLListView.Items.Add(href);
URLLMemoRichTxt.Text += href + "\n";
URLListCountLBL.Text = URLLMemoRichTxt.Lines.Length.ToString();
// GetInnerLink(href);
}
}
}
AddLog("All links has been scrapped successfully for \r\n" + currentURL);
Application.ExitThread(); // Stops the thread
}
}
Already found a solution myself :
replaced :
URLLMemoRichTxt.Text += href + "\n";
With :
URLLMemoRichTxt.AppendText(Environment.NewLine + href);

Serial Communication Port will get Closed after clicking on Close button in C#

I am working on project in C# windows form application.
In this project main Form contain subform for communication of serial port. SubForm "Connect" have two buttons Connect and Close. Also 5 comboboxes to select baudrate, Com name,parity, stopbits and databits.
When I click on Connect button after selecting all settings from comboboxes. port gets connected and connect button becomes Disconnect. And I will close the Connect form
Now my problem is that when I reopen the form, without clicking on Disconnect button when i Close the form , the Comport will disconnected. I don't want that ComPort close.
Please help me to solve this bug. I don't know where I did mistake. Thanks in advance.
Connect Class Code
public partial class Connect : Form
{
public bool Connect_Status = false;
public Connect()
{
InitializeComponent();
COM_List();
}
private void COM_List()
{
for (int i = 0; i < CommPortManager.Instance.GetCommList().Count; i++)
{
cb_CommPort.Items.Add(CommPortManager.Instance.GetCommList()[i]);
}
}
private void btn_Connect_Click(object sender, EventArgs e)
{
if (btn_Connect.Text == "Connect")
{
CommPortManager.Instance.PortName = cb_CommPort.Text;
CommPortManager.Instance.BaudRate = cb_BaudRate.Text;
CommPortManager.Instance.Parity = cb_Parity.Text;
CommPortManager.Instance.StopBits = cb_StopBits.Text;
CommPortManager.Instance.DataBits = cb_DataBits.Text;
if ((cb_CommPort.Text == "") || (cb_BaudRate.Text == "") || (cb_Parity.Text == "") || (cb_DataBits.Text == "") || (cb_StopBits.Text == ""))
{
if (cb_CommPort.Text == "")
{
MessageBox.Show("Please select COM Port and then Connect", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (cb_BaudRate.Text == "")
{
MessageBox.Show("Please select BaudRate and then Connect", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (cb_Parity.Text == "")
{
MessageBox.Show("Please select Parity and then Connect", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (cb_DataBits.Text == "")
{
MessageBox.Show("Please select DataBits and then Connect", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if(cb_StopBits.Text == "")
{
MessageBox.Show("Please select StopBits and then Connect", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Connect_Status = false;
}
else
{
if (CommPortManager.Instance.COM_Open() == false)
{
MessageBox.Show("Could not open the COM port. Most likely it is already in use, has been removed, or is unavailable.", "TestCertificate", MessageBoxButtons.OK, MessageBoxIcon.Information);
Connect_Status = false;
}
else
{
//CommPortManager.Instance.COM_Close();
Connect_Status = true;
btn_Connect.Text = "Disconnect";
cb_CommPort.Enabled = false;
cb_BaudRate.Enabled = false;
cb_DataBits.Enabled = false;
cb_Parity.Enabled = false;
cb_StopBits.Enabled = false;
btn_Connect.BackColor = System.Drawing.Color.Salmon;
}
}
}
else
{
CommPortManager.Instance.COM_Close();
btn_Connect.Text = "Connect";
Connect_Status = false;
cb_CommPort.Enabled = true;
cb_BaudRate.Enabled = true;
cb_DataBits.Enabled = true;
cb_Parity.Enabled = true;
cb_StopBits.Enabled = true;
btn_Connect.BackColor = System.Drawing.Color.DarkTurquoise;
}
}
private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}
private void Connect_Load(object sender, EventArgs e)
{
//code here to setup the value;
cb_CommPort.Text = CommPortManager.Instance.PortName;
cb_BaudRate.Text = CommPortManager.Instance.BaudRate;
cb_Parity.Text = CommPortManager.Instance.Parity;
cb_StopBits.Text = CommPortManager.Instance.StopBits;
cb_DataBits.Text = CommPortManager.Instance.DataBits;
if (CommPortManager.Instance.IsOpen == true)
{
btn_Connect.Text = "Disconnect";
btn_Connect.BackColor = System.Drawing.Color.Salmon;
cb_CommPort.Enabled = false;
cb_BaudRate.Enabled = false;
cb_DataBits.Enabled = false;
cb_Parity.Enabled = false;
cb_StopBits.Enabled = false;
}
else
{
btn_Connect.Text = "Connect";
Connect_Status = false;
cb_CommPort.Enabled = true;
cb_BaudRate.Enabled = true;
cb_DataBits.Enabled = true;
cb_Parity.Enabled = true;
cb_StopBits.Enabled = true;
btn_Connect.BackColor = System.Drawing.Color.DarkTurquoise;
}
}
}
I suspect that the form load event. you need to set the connection status true when its open
private void Connect_Load(object sender, EventArgs e)
{
//code here to setup the value;
cb_CommPort.Text = CommPortManager.Instance.PortName;
cb_BaudRate.Text = CommPortManager.Instance.BaudRate;
cb_Parity.Text = CommPortManager.Instance.Parity;
cb_StopBits.Text = CommPortManager.Instance.StopBits;
cb_DataBits.Text = CommPortManager.Instance.DataBits;
if (CommPortManager.Instance.IsOpen == true)
{
Connect_Status = true;
btn_Connect.Text = "Disconnect";
btn_Connect.BackColor = System.Drawing.Color.Salmon;
cb_CommPort.Enabled = false;
cb_BaudRate.Enabled = false;
cb_DataBits.Enabled = false;
cb_Parity.Enabled = false;
cb_StopBits.Enabled = false;
}
else
{
btn_Connect.Text = "Connect";
Connect_Status = false;
cb_CommPort.Enabled = true;
cb_BaudRate.Enabled = true;
cb_DataBits.Enabled = true;
cb_Parity.Enabled = true;
cb_StopBits.Enabled = true;
btn_Connect.BackColor = System.Drawing.Color.DarkTurquoise;
}
}
It looks like that if you press Connect it changes your btn_Connect.Text to
Disconnect (if the port is open)
now the button text is "Disconnect" and if (btn_Connect.Text == "Connect") is now false and the else is called which does CommPortManager.Instance.COM_Close();

how to release thread is required in multiple thread?

As title, how to release thread is required in multiple thread ?
Ex : I have 5 thread is waiting. I only want thread position 3 is released
I use autoresetevent/manualresetevent/monitor.wait and monitor.pulse but all release thread follow FIFO
help me !!!
UPDATED:
This is form1:
private BackgroundWorker[] threadArray;
public static ManualResetEvent _manualResetEvent = new ManualResetEvent(false);
private void btn_Start_Scraping_Click(object sender, EventArgs e)
{
threadArray = new BackgroundWorker[listView_Site.Items.Count];
for (var f = 0; f < listView_Site.Items.Count; f++)
{
threadArray[f] = new BackgroundWorker();
threadArray[f].DoWork += new DoWorkEventHandler(BackgroundWorkerFilesDoWork);
threadArray[f].RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerFilesRunWorkerCompleted);
threadArray[f].ProgressChanged += new ProgressChangedEventHandler(BackgroundWorkerFilesProgressChanged);
threadArray[f].WorkerReportsProgress = true;
threadArray[f].WorkerSupportsCancellation = true;
threadArray[f].RunWorkerAsync(listView_Site.Items[f].Tag.ToString());
}
}
private void BackgroundWorkerFilesDoWork(object sender, DoWorkEventArgs e)
{
....// all above code is fine
requestCaptcha = (HttpWebRequest)WebRequest.Create(uriCaptchaPage);
requestCaptcha.Pipelined = true;
requestCaptcha.KeepAlive = true;
requestCaptcha.AllowAutoRedirect = false;
//request.Proxy = null;
requestCaptcha.Timeout = 60000;
requestCaptcha.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
requestCaptcha.CookieContainer = sessionID;
request.ServicePoint.Expect100Continue = false;
requestCaptcha.Method = "GET";
requestCaptcha.Referer = uriloginPage.AbsoluteUri;
//get response.
responseCaptcha = (HttpWebResponse)requestCaptcha.GetResponse();
Stream imagestream = responseCaptcha.GetResponseStream();
if (imagestream != null)
{
Image image = Image.FromStream(imagestream);
if (Directory.Exists(Application.StartupPath + "\\Captcha") == false)
{
Directory.CreateDirectory(Application.StartupPath + "\\Captcha");
}
switch (responseCaptcha.ContentType)
{
case "image/jpeg":
{
saveLocation += ".jpg";
if (File.Exists(saveLocation))
{
File.Delete(saveLocation);
}
image.Save(saveLocation,ImageFormat.Jpeg);
break;
}
case "image/gif":
{
saveLocation += ".gif";
if (File.Exists(saveLocation))
{
File.Delete(saveLocation);
}
image.Save(saveLocation, ImageFormat.Gif);
break;
}
case "image/png":
{
saveLocation += ".png";
if (File.Exists(saveLocation))
{
File.Delete(saveLocation);
}
image.Save(saveLocation, ImageFormat.Png);
break;
}
}
//show form2 to enter captcha
lock (_lockObj)
{
if (Application.OpenForms.OfType<frmCaptchaQuestion>().Any() == false)
{
DoOnUIThread(delegate()
{
_formCaptchaQuestion.CreatePanelCaptcha(uriloginPage, saveLocation,idHomePage);
_formCaptchaQuestion.Show();
});
}
else
{
DoOnUIThread(() => _formCaptchaQuestion.CreatePanelCaptcha(uriloginPage, saveLocation,idHomePage));
}
}
//wait and get captcha from form2 and only run thread is required
//this is my problem <<<<========================================
lock (_lockObj)
{
//_manualResetEvent.WaitOne(30000);
//_manualResetEvent.Reset();
//if (clsValueStatic.CaptchaText != null)
//{
// foreach (var id in clsValueStatic.CaptchaText)
// {
while (!_go)
{
Monitor.Wait(_lockObj);
}
// }
//}
}
requestCaptcha = (HttpWebRequest)WebRequest.Create(uriActionLoginPage);
requestCaptcha.Pipelined = true;
requestCaptcha.KeepAlive = true;
requestCaptcha.AllowAutoRedirect = false;
//request.Proxy = null;
requestCaptcha.Timeout = 60000;
requestCaptcha.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
requestCaptcha.CookieContainer = sessionID;
request.ServicePoint.Expect100Continue = false;
requestCaptcha.Method = "GET";
}
Form2:
private void textBoxCaptcha_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
var textBox = sender as TextBoxX;
if (textBox != null)
{
clsValueStatic.CaptchaText = textBox.Text.Trim();
textBox.Parent.Parent.Dispose();
frmScrapingAnalysis._manualResetEvent.Set();
}
}
}
PS : Form1 have 1 button to start multiple backgroundworker and show form2 then all backgroundworker wait to get text captcha of textbox from form2
my way want when user enter text of backgroundworker is shown on form2 then only the backgroundworker is released. All other backgroundworker still wait

APM pattern, Await Async

I need help on how to use APM pattern, i am now reading some articles, but i am afraid i don't have much time. What i really want is to get all the persons(data from db) then get the photos and put it on a autocompletebox
Code:
void listanomesautocomplete(object sender, ServicosLinkedIN.queryCompletedEventArgs e)
{
if (e.Result[0] != "")
{
for (int i = 0; i < e.Result.Count(); i = i + 3)
{
Pessoa pessoa = new Pessoa();
pessoa.Nome = e.Result[i];
pessoa.Id = Convert.ToInt32(e.Result[i + 1]);
if (e.Result[i + 2] == "")
pessoa.Imagem = new BitmapImage(new Uri("Assets/default_perfil.png", UriKind.Relative));
else
{
ServicosLinkedIN.ServicosClient buscaimg = new ServicosLinkedIN.ServicosClient();
buscaimg.dlFotoAsync(e.Result[i + 2]);
buscaimg.dlFotoCompleted += buscaimg_dlFotoCompleted;//when this completes it saves into a public bitmapimage and then i save it into pessoa.Imagem
//basicly, what happends, the listadlfotosasync only happends after this function
//what i want is to wait until it completes and have into the class novamsg
pessoa.Imagem = img;//saving the photo from dlFotoAsync
}
listaPessoas.Add(pessoa);
}
tbA_destinatario.ItemsSource = null;
tbA_destinatario.ItemsSource = listaPessoas;
BackgroundWorker listapessoas = new BackgroundWorker();
listapessoas.DoWork += listapessoas_DoWork;
listapessoas.RunWorkerAsync();
tb_lerdestmsg.Text = "";
}
else
{
tbA_destinatario.ItemsSource = null;
tb_lerdestmsg.Text = "Não encontrado";
}
}
There are a few things to address here:
The listanomesautocomplete event handler should be async. Handle and report all exceptions possibly thrown inside it (generally, this rule applies to any event handler, but it's even more important for async event handlers, because the asynchronous operation inside your handler continues outside the scope of the code which has fired the event).
Register the dlFotoCompleted event handler first, then call dlFotoAsync. Do not assume that dlFotoAsync will be always executed asynchronously.
Think about the case when another listanomesautocomplete is fired while the previous operation is still pending. This well may happen as a result of the user's action. You may want to cancel and restart the pending operation (like this), or just queue a new one to be executed as soon as the pending one has completed (like this).
Back to the question, it's the EAP pattern that you need to wrap as Task, not APM. Use TaskCompletionSource for that. The relevant part of your code may look like this:
async void listanomesautocomplete(object sender, ServicosLinkedIN.queryCompletedEventArgs e)
{
if (e.Result[0] != "")
{
for (int i = 0; i < e.Result.Count(); i = i + 3)
{
Pessoa pessoa = new Pessoa();
pessoa.Nome = e.Result[i];
pessoa.Id = Convert.ToInt32(e.Result[i + 1]);
if (e.Result[i + 2] == "")
pessoa.Imagem = new BitmapImage(new Uri("Assets/default_perfil.png", UriKind.Relative));
else
{
// you probably want to create the service proxy
// outside the for loop
using (ServicosLinkedIN.ServicosClient buscaimg = new ServicosLinkedIN.ServicosClient())
{
FotoCompletedEventHandler handler = null;
var tcs = new TaskCompletionSource<Image>();
handler = (sHandler, eHandler) =>
{
try
{
// you can move the code from buscaimg_dlFotoCompleted here,
// rather than calling buscaimg_dlFotoCompleted
buscaimg_dlFotoCompleted(sHandler, eHandler);
tcs.TrySetResult(eHandler.Result);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
};
try
{
buscaimg.dlFotoCompleted += handler;
buscaimg.dlFotoAsync(e.Result[i + 2]);
// saving the photo from dlFotoAsync
pessoa.Imagem = await tcs.Task;
}
finally
{
buscaimg.dlFotoCompleted -= handler;
}
}
}
listaPessoas.Add(pessoa);
}
tbA_destinatario.ItemsSource = null;
tbA_destinatario.ItemsSource = listaPessoas;
BackgroundWorker listapessoas = new BackgroundWorker();
listapessoas.DoWork += listapessoas_DoWork;
listapessoas.RunWorkerAsync();
tb_lerdestmsg.Text = "";
}
else
{
tbA_destinatario.ItemsSource = null;
tb_lerdestmsg.Text = "Não encontrado";
}
}
void listanomesautocomplete(object sender, ServicosLinkedIN.queryCompletedEventArgs e)
{
if (e.Result[0] != "")
{
List<Pessoa> listaPessoas = new List<Pessoa>();
for (int i = 0; i < e.Result.Count(); i = i + 3)
{
Pessoa pessoa = new Pessoa();
pessoa.Nome = e.Result[i];
pessoa.Id = Convert.ToInt32(e.Result[i + 1]);
if (e.Result[i + 2] == "")
pessoa.Imagem = new BitmapImage(new Uri("Assets/default_perfil.png", UriKind.Relative));
else
{
ServicosLinkedIN.ServicosClient buscaimg = new ServicosLinkedIN.ServicosClient();
buscaimg.dlFotoAsync(e.Result[i + 2]);
//THIS ACTUALLY WORKS!!!
//THE THREAD WAITS FOR IT!
buscaimg.dlFotoCompleted += (s, a) =>
{
pessoa.Imagem = ConvertToBitmapImage(a.Result);
};
}
listaPessoas.Add(pessoa);
}
if (tbA_destinatario.ItemsSource == null)
{
tbA_destinatario.ItemsSource = listaPessoas;
}
tb_lerdestmsg.Text = "";
}
else
{
tbA_destinatario.ItemsSource = null;
tb_lerdestmsg.Text = "Não encontrado";
}
}
Man, i am not even mad, i am amazed.
Noseratio, you answer gave me an idea and it actually worked!!
Thanks a lot man, i can't thank you enough ;)

if else with checkbox and string

could someone help me figure out what I am doing wrong. I have tried so many ways and can't get it to work in all cases at same time.
Our symbol devices have multiple firmware versions that cause issues with the wireless card in the device. if the firmware version is 86.09.0000 it will work fine. If the firmware version if anything else "01.09.000" it will cause issues so i have it dump a cab file with factory firmware and reboot device.
Thanks for help, below is working code.
if (checkBox1.Checked && myString == "86.09.0000")
{
//check box checked and correct string
}
else if ((checkBox1.Checked == false) && (myString == "86.09.0000"))
{
//check box not checked and correct string
}
else
{
// string doesn't match
}
I would assume you mean if myString isn't 86.09.0000... Is your final else in the wrong 'if' statement?
if (checkBox1.Checked && myString == "86.09.0000")
{
wipefiles();
}
else if ((checkBox1.Checked == false) && (myString == "86.09.0000"))
{
if (myThread == null)
{
label4.Visible = false;
pictureBox1.Enabled = false;
SystemIdleTimerReset();
menuItem1.Enabled = false;
myThread = new Thread(MyWorkerThread);
myThread.IsBackground = true;
myThread.Start();
}
}
else
{
MessageBox.Show("Install firmware");
}
Is this possibly what you were trying to accomplish?
Private void menuItem1_Click(object sender, EventArgs e)
{
String oemVersion = oemver.getOEMVersion();
String myVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
if (myVersion.Equals(oemVersion))
{
if (checkBox1.Checked)
wipefiles();
else
{
if (myThread == null)
{
label4.Visible = false;
pictureBox1.Enabled = false;
SystemIdleTimerReset();
menuItem1.Enabled = false;
myThread = new Thread(MyWorkerThread);
myThread.IsBackground = true;
myThread.Start();
}
}
}
else
{
MessageBox.Show("Install firmware");
}
}
Simply add another "OR" || condition in your if statement .See below
if (checkBox1.Checked && (myString == "86.09.0000"***||myString="01.09.000"***))
{
wipefiles();
}
else if ((checkBox1.Checked == false) && (myString == "86.09.0000"***||myString="01.09.000"***))
{
if (myThread == null)
{
label4.Visible = false;
pictureBox1.Enabled = false;
SystemIdleTimerReset();
menuItem1.Enabled = false;
myThread = new Thread(MyWorkerThread);
myThread.IsBackground = true;
myThread.Start();
}
}
else
{
MessageBox.Show("Install firmware");
}
Now It's working for you ! But it's not good .Because it's maay be going to lot of "OR" condition . So Please assign the mystring value from when code running!

Categories

Resources