ה SR מוגדר ברמת הקלאס של הקלאס Options_File namespace DannyGeneral { class OptionsFile { /*---------------------------------------- * P R I V A T E V A R I A B L E S * ---------------------------------------*/
/*--------------------------------- * P U B L I C M E T H O D S * -------------------------------*/ string path_exe; string temp_settings_file; string temp_settings_dir; string Options_File; StreamWriter sw; StreamReader sr;
|
והבעיה הייתה ברמת הקונסטרקטור של הקלאס Options_File בפעם הראשונה שמישהו מפעיל את התוכנה אחרי התקנה הוא יוצר קובץ settings.txt והקובץ נשאר פתוח .
לכן עשיתי :
public OptionsFile(string settings ) { if (File.Exists(settings)) { } else { FileStream fs=File.Create(settings); fs.Close(); } path_exe = Path.GetDirectoryName(Application.LocalUserAppDataPath); Options_File = settings; }
|
השתמשתי ב FILESTREAM וסגרתי את הקובץ אחרי שנוצר עם ה FS .