473,398 Members | 2,380 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,398 software developers and data experts.

Events not always called depending on application type

Hello newsgroup

I'm using a library to discover UPnP devices on the network via sockets.
Its use is pretty straightforward:

private void Discover()
DevDiscovery disco = new DevDiscovery ();
disco.OnAddedDevice += new DevDiscovery.DiscoveryHandler(OnAdded);

disco.Start();
}

This code works always, when placed within a main-method market with a
[STAThread]-attribute (console app or winform). I'm quite sure it works
always with this code within a windows form if I'm using Invoke():

protected override void OnHandleCreated(EventArgs e)
{
Invoke(new MethodInvoker(Discover));
}

But is does *not* work always, if I'm starting the discovery from within
a windows form control! Sometimes, the event handlers are being called,
sometimes not. I guess, it's about the threading model, but I have no
clue how to solve it...

Thanks for your advice

Philipp

Nov 15 '05 #1
2 1332
Philipp,

It is possible that the threading model has something to do with it,
depending on whether or not COM interop is involved. However, I see a
bigger problem. Basically, the Discover method is creating an instance of
DevDiscovery, and immediately letting go of the reference. This will
continue to fire events until there is a garbage collection, at which point
it is going to stop listening and stop firing events. You need to store
this reference somewhere so that you have an active object that can fire
events and receive the UPnP notifications.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Philipp Sumi" <ph*****@nospam123.net> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hello newsgroup

I'm using a library to discover UPnP devices on the network via sockets.
Its use is pretty straightforward:

private void Discover()
DevDiscovery disco = new DevDiscovery ();
disco.OnAddedDevice += new DevDiscovery.DiscoveryHandler(OnAdded);

disco.Start();
}

This code works always, when placed within a main-method market with a
[STAThread]-attribute (console app or winform). I'm quite sure it works
always with this code within a windows form if I'm using Invoke():

protected override void OnHandleCreated(EventArgs e)
{
Invoke(new MethodInvoker(Discover));
}

But is does *not* work always, if I'm starting the discovery from within
a windows form control! Sometimes, the event handlers are being called,
sometimes not. I guess, it's about the threading model, but I have no
clue how to solve it...

Thanks for your advice

Philipp

Nov 15 '05 #2
Hello Nicholas

Great observation - I just took over the automatically generated
discovery code without considering the environment in my application. I
could just make a short trial but could not reproduce the error with the
fixed code :-)

Thank you very much!

Philipp

Nicholas Paldino [.NET/C# MVP] wrote:
Philipp,

It is possible that the threading model has something to do with it,
depending on whether or not COM interop is involved. However, I see a
bigger problem. Basically, the Discover method is creating an instance of
DevDiscovery, and immediately letting go of the reference. This will
continue to fire events until there is a garbage collection, at which point
it is going to stop listening and stop firing events. You need to store
this reference somewhere so that you have an active object that can fire
events and receive the UPnP notifications.

Hope this helps.


Nov 15 '05 #3

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

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
5
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so...
2
by: Gary W. Smith | last post by:
I have a page that inherits from a base page that is currently overriding all of the On* events. For the most part I'm accomplishing everything I set out to do with the inheritance, but I wanted...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.