I am building a file watcher that loads data from a file that is dropped to a specified location in SQL. All my code is fine, except the passing of variables typed in TextBoxes in the UI to another class outside of MainWindow.
First I initialize a FileWatcher:
public MainWindow()
{
InitializeComponent();
FileWatch.FileWatcherLoad();
}
Which calls the file watcher to initialize:
public static void FileWatcherLoad()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = //some path;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
This issue is arising because the MainWindow is forcing me to declare FileWatcherLoad as a static type. When I remove the static type from File WatcherLoad() I get error:
an object reference is required for the non-static field, method or property 'FileWatch.FileWatcherLoad()'
Note that FileWatcherLoad() is in another class, FileWatch, which is a child class of MainWindow.
This is an issue for me because I wish to use user-entered data in a textbox in my UI, but this is NON STATIC, and is therefore causing a problem when I declare everything else static.