Event handling
- From: "David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Oct 2008 16:38:30 -0000
Hi all,
I am currently writing an app for a mobile phone. (WM6) with Compact
Framework, though this probably has no bearing on my question.
I am building the app as a layered app. I have my main screen, but behind
this, I have for example, a class that talks to the bluetooth device.
So, for example...
Form1.cs
Here I have...
Bluetooth bt = new Bluetooth();
bt.Connect(); // Asks the bluetooth connection to start and be ready to
handle incoming files.
classes\Bluetooth.cs
public void Connect()
{
// Do my bluetooth actions.
// This also starts a thread.
}
private void BTThreadHandler()
{
// This is the thread handler that was started in connect.
// This saves a file.
}
What I need to do is to allow the BTThreadHandler to notify Form1.cs when a
file has arrived. I actually need to pass the filename. I could store the
filename in a property but if another file comes in, the property will no
doubt change, so a property is not really safe in this instance.
For the event handler, in the past, I have done something like this, but I
don't know if this would be normal... is it?
Form1.cs
bt.EventUpdateData += new EventHandler(CollectDataHandler);
private void CollectDataHandler(object sender, EventArgs e)
{
// handle the event
}
classes\Bluetooth.cs
public event EventHandler EventUpdateData;
private void BTThreadHandler()
{
// This is the thread handler that was started in connect.
// This saves a file.
// Create an event
if (EventUpdateData != null)
EventUpdateData(sender, e); // Note, this is copied, so
sender and e are not valid here.
}
Is this how it is done?
I guess that to pass the filename string, instead of using sender and e, I
just send the string.
Your advice is appreciated. If the above is the wrong way, I would
appreciate the details of how it should be done.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
.
- Follow-Ups:
- Re: Event handling
- From: sloan
- Re: Event handling
- Prev by Date: Re: Application design
- Next by Date: Re: Event handling
- Previous by thread: papersources and papersizes really slow on some systems.
- Next by thread: Re: Event handling
- Index(es):
Relevant Pages
|