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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Posted Jul 30, 2014, 12:43 AM EDT
Can you explain your requirement with conditions you want implement.
Thanks
Kailash
Paras Kharbanda46 reputationPosted Jul 30, 2014, 4:20 AM EDT
Posted Jul 30, 2014, 4:56 AM EDT
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