In my app (in c#) i want to execute a method only once in whole application such that if i start the application again then that method shouldn't execute or call again.
Can anyone help me in this problem?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jul 30, 2014, 8:56 AM
In Programm class (Start up Class) and within the static method try to check the data is exist in registry or not. if not exist then call your method, and if not exist then call the your method.
Code
string filename;
string KeyName="your registry key name where your text exist";
// Opening the registry key
RegistryKey rk = baseRegistryKey ;
// Open a subKey as read-only
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistrySubKey doesn't exist -> (null)
if ( sk1 == null )
{
//Call Method
}
else
{
try
{
// If the RegistryKey exists I get its value // or null is returned.
filename= (string)sk1.GetValue(KeyName.ToUpper());
}
catch (Exception e)
{
// AAAAAAAAAAARGH, an error!
MessageBox.Show(e, "Reading registry " + KeyName.ToUpper());
}
}
if(File.Exists("full path")==true)
{
MessageBox.Show("File Exists");
}
else
{
MessageBox.Show("File not Exists");
}
Kindly mark as answer , if it helps to you
Thanks,
Kailash
Paras KharbandaPosted Jul 30, 2014, 8:20 AM
Posted Jul 30, 2014, 4:43 AM
Can you explain your requirement with conditions you want implement.
Thanks
Kailash