I have created an console application which i am scheduling in Task Scheduler as job. I have one class level Static variable in my application, below is the sample code. When my job runs for the first time, no issue. When i rerun the job immediately, I get "Object reference" error as I am setting it to NULL in finally block and doing "sb.clear()" in try block - static variable will be initialized only once.
Class Temp
{
public static StringBuilder sb = new StringBuilder();
try
{
sb.clear();
... some code
}
catch
{}
finally
{
sb = null
}
}
My Task Scheduler job will run on every 24 hours. Since i set the variable to NULL, will this be Garbage collected after some time of first run? This way i wont run into "Object Reference" error when my job runs for second time after 24 hours (considering static variable will be created again).
I want to know what is the life time of static variable if i set this to NULL and if not i set this to NULL. Please clarify.