I am wrtining my first c# app that will monitor a perticular file location to do things.
When I build the project I get :
An object reference is required for the nonstatic field, method, or property JobMonitor.StartUp.watcher at:
watcher.Star ch();
Here is the code:
using System;
using System.Windows.Forms;
namespace JobMonitor
{
/// <summary>
/// Summary description for Main.
/// </summary>
public class StartUp
{
FileWatch watcher = new FileWatch();
static void Main()
{
watcher.Star ch(); // <-- error at this point
Application.Run(new frmFortestingonly());
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace JobMonitor
{
/// <summary>
/// Summary description for FileWatch.
/// </summary>
public class FileWatch
{
FileSystemWatcher watcher = new FileSystemWatcher();
public FileWatch()
{
}
public void Star ch()
{
watcher.Path = "D:\\";
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Attributes
| NotifyFilters.LastAccess | NotifyFilters.LastWrite |
NotifyFilters.Security | NotifyFilters.Size;
watcher.Changed += new FileSystemEventHandler(OnFileEvent);
watcher.Created += new FileSystemEventHandler(OnFileEvent);
watcher.EnableRaisingEvents = true;
}
//-----------------------------------------------------------------------
public void OnFileEvent(object source, FileSystemEventArgs fsea)
{
DateTime dt = new DateTime();
dt = System.DateTime.UtcNow;
MessageBox.Show("",dt.ToLocalTime() + " " + fsea.ChangeType.ToString() + " " + fsea.FullPath) ;
}
//----------------------------------------------------------------------
public void OnRenameEvent(Object source, RenamedEventArgs rea)
{
DateTime dt = new DateTime();
dt = System.DateTime.UtcNow;
MessageBox.Show("",dt.ToLocalTime() + " " + rea.ChangeType.ToString() + rea.OldFullPath+ " to " +" " + rea.FullPath);
}
//------------------------------------------------------------------
}
}
Any help would be great.
Thanks
When I build the project I get :
An object reference is required for the nonstatic field, method, or property JobMonitor.StartUp.watcher at:
watcher.Star ch();
Here is the code:
using System;
using System.Windows.Forms;
namespace JobMonitor
{
/// <summary>
/// Summary description for Main.
/// </summary>
public class StartUp
{
FileWatch watcher = new FileWatch();
static void Main()
{
watcher.Star ch(); // <-- error at this point
Application.Run(new frmFortestingonly());
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace JobMonitor
{
/// <summary>
/// Summary description for FileWatch.
/// </summary>
public class FileWatch
{
FileSystemWatcher watcher = new FileSystemWatcher();
public FileWatch()
{
}
public void Star ch()
{
watcher.Path = "D:\\";
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Attributes
| NotifyFilters.LastAccess | NotifyFilters.LastWrite |
NotifyFilters.Security | NotifyFilters.Size;
watcher.Changed += new FileSystemEventHandler(OnFileEvent);
watcher.Created += new FileSystemEventHandler(OnFileEvent);
watcher.EnableRaisingEvents = true;
}
//-----------------------------------------------------------------------
public void OnFileEvent(object source, FileSystemEventArgs fsea)
{
DateTime dt = new DateTime();
dt = System.DateTime.UtcNow;
MessageBox.Show("",dt.ToLocalTime() + " " + fsea.ChangeType.ToString() + " " + fsea.FullPath) ;
}
//----------------------------------------------------------------------
public void OnRenameEvent(Object source, RenamedEventArgs rea)
{
DateTime dt = new DateTime();
dt = System.DateTime.UtcNow;
MessageBox.Show("",dt.ToLocalTime() + " " + rea.ChangeType.ToString() + rea.OldFullPath+ " to " +" " + rea.FullPath);
}
//------------------------------------------------------------------
}
}
Any help would be great.
Thanks