473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Event Handler not updating another class's forms

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
Apr 9 '06 #1
2 1588
Hi,

This is one of those things you want to try and see it happening for
yourself before you can really give super advise. That said I would
ask if you're using Invoke or BeginInvoke to make sure that any
accesses of a form's controls happen on that form's main thread.

If you want more details on this give me a shout.

Nick

Apr 9 '06 #2
Nick, I think you're right; thanks for that. I'm continuing to work through
this, but just wanted to let you know I saw your answer, and hopefully it
will get me going in the right direction. I'll try to post back when it's
done. Actually, when I get done the app I want to do, I'll probably try to
submit it to the CodeProject website.

Clint

"nick_nw" <ng****@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi,

This is one of those things you want to try and see it happening for
yourself before you can really give super advise. That said I would
ask if you're using Invoke or BeginInvoke to make sure that any
accesses of a form's controls happen on that form's main thread.

If you want more details on this give me a shout.

Nick

Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
10
by: SunshineGirl | last post by:
In my code, class A instanciates classes B and C. I would like class B to connect an event handler to a method in class A, and for class C to disconnect that event handler. I think I've done...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
7
by: Michael D. Ober | last post by:
Is there anyway to raise an event from a class and require that any program using that class (not just inheritance) have an event handler for specific events in the class? In my case, some events...
16
by: tommaso.gastaldi | last post by:
Hello, A probably dumb question... does anyone know hot to avoid that if one keep the mouse pressed on an arrow of the numericUpDown it continues to fire events (it uses evidently a timer) ?...
0
by: Paul Hadfield | last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet 2.0 - in winforms, but that's not so important). I've got two combo boxes (combo1 and combo2), both are populating via...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.