Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a method from a static routine c#
    text
    copied!<p>I have a method as</p> <pre><code> private string sLogFormat; private string sErrorTime; public void CreateLogFile(string path, string msg) { //sLogFormat used to create log files format : // dd/mm/yyyy hh:mm:ss AM/PM ==&gt; Log Message sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==&gt; "; //this variable used to create log filename format " //for example filename : ErrorLogYYYYMMDD string sYear = DateTime.Now.Year.ToString(); string sMonth = DateTime.Now.Month.ToString(); string sDay = DateTime.Now.Day.ToString(); sErrorTime = sYear + sMonth + sDay; StreamWriter sw = new StreamWriter(path + sErrorTime, true); sw.WriteLine(sLogFormat + msg); sw.Flush(); sw.Close(); } </code></pre> <p>Another method run() that triggers somewhere the Onchanged handler(it is triggered when folder content is changed more precisely) here </p> <pre><code> public static void Run() { // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "C:/model_RCCMREC"; /* Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // watch wav files. watcher.Filter = "*.wav"; // Add event handlers. watcher.Created += new FileSystemEventHandler(OnChanged); // Begin watching. watcher.EnableRaisingEvents = true; } </code></pre> <p>and the OnChanged handler as </p> <pre><code>public static void OnChanged(object source, FileSystemEventArgs e) { try { //access last folder(newly created one is suposedly at last position) var directory = new DirectoryInfo("C:/model_RCCMREC"); var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First(); //2.Split the file name. } catch { //I WANT TO ACCESS THE METHOD CreateLogFile(x,y) HERE } } </code></pre> <p>I cannot access the method CreateLogFile() from the OnChanged handler normally.How can i access it ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload