Hopefully I can explain the situation clearly. If not, I've got a project
that does.
I've created a C# application that sets up a FileSystemEventHandler event to
monitor a particular directory for the creation of a particular type of
file. At first glance, everything seems just hunky-dory. The event fires
when I want it to, and a message box was displayed.
So I thought, well, let's take it to the next level. Let's put in a funky
Outlook-style pop-up in the bottom left corner of the screen. So first off,
I created a separate class that contained the form, controls and code to do
what I wanted it to do. I dropped an extra button on my form to test the new
functionality, and it works great.
So now, I've got two pieces of code, both of them work fine separately.
There's only about 10 lines of actual code, and it should just be a matter
of copying the code from the preview button to the event handler of the
FileSystemEventHandler. Right? But now, when I do that, all that happens
is is the form appears, but the text boxes and colors aren't updated, and
when I move my mouse over the form, it just shows an hour-glass. Task
Manager shows minimal CPU activity, however. If I comment out my new code,
and just use the MessageBox again, it works fine.
I've also tried this with a form that's part of the same application, with
the same effect.
Here's the code I've got that uses the separate class:
private void btnStartMonitoring_Click(object sender, EventArgs e)
{
System.IO.FileSystemWatcher fsw = new
FileSystemWatcher(txtDirectoryName.Text.ToString() );
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite |
NotifyFilters.FileName | NotifyFilters.DirectoryName;
fsw.Filter = "*.cnk";
fsw.Created += new FileSystemEventHandler(OnCreated);
// Begin watching.
fsw.EnableRaisingEvents = true;
}
private static void OnCreated(object source, FileSystemEventArgs e)
{
string sMessage = "File: " + e.FullPath + " " + e.ChangeType;
//MessageBox.Show(sMessage); //if I un-comment this line, and comment
out the rest of this code, it works fine.
Notifier.Notifier notifier = new Notifier.Notifier();
notifier.DisplayNotification("This sucks"); //this function just updates
a text box on the notifier form.
}
private void btnShowMessage_Click(object sender, EventArgs e)
{
//This is my "Preview" button.
Notifier.Notifier notifier = new Notifier.Notifier();
notifier.DisplayNotification(txtMessage.Text.ToStr ing());
}
Clint