473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static events

Hi,

I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?
Apr 2 '08 #1
10 2967
On Apr 2, 12:32 pm, parez <psaw...@gmail. comwrote:
Hi,

I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?
Its a winforms application .net 3.0
Apr 2 '08 #2
On Apr 2, 11:33*am, parez <psaw...@gmail. comwrote:
On Apr 2, 12:32 pm, parez <psaw...@gmail. comwrote:
Hi,
I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?

Its a winforms application .net *3.0
If I remember correctly, it is not thread safe, if you are using any
volitle resource I would suggest locking them.

lock(var)
{
}

Thanks.
Apr 2 '08 #3
On Wed, 02 Apr 2008 09:32:47 -0700, parez <ps*****@gmail. comwrote:
I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?
Thread safety is as much an issue as it would be with an instance event.
The only difference is that with a static event you don't have the option
of dedicating an instance to each thread as a way of solving the thread
safety issues.

Otherwise, it's the same and you'd address the issues in the same way.

Pete
Apr 2 '08 #4
On Apr 2, 1:02 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 02 Apr 2008 09:32:47 -0700, parez <psaw...@gmail. comwrote:
I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?

Thread safety is as much an issue as it would be with an instance event.
The only difference is that with a static event you don't have the option
of dedicating an instance to each thread as a way of solving the thread
safety issues.

Otherwise, it's the same and you'd address the issues in the same way.

Pete
Thanks..

that means static and instance event in singleton would make no
difference?

TIA
Apr 2 '08 #5
On Wed, 02 Apr 2008 10:45:55 -0700, parez <ps*****@gmail. comwrote:
that means static and instance event in singleton would make no
difference?
With respect to thread safety? Yes, no difference.

Pete
Apr 2 '08 #6
Peter Duniho wrote:
On Wed, 02 Apr 2008 10:45:55 -0700, parez <ps*****@gmail. comwrote:
>that means static and instance event in singleton would make no
difference?

With respect to thread safety? Yes, no difference.
No difference once the singleton is set up... creating the singleton only
once raises some new thread safety issues, especially if it is done lazily.
>
Pete

Apr 2 '08 #7
On Apr 2, 12:45*pm, parez <psaw...@gmail. comwrote:
On Apr 2, 1:02 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 02 Apr 2008 09:32:47 -0700, parez <psaw...@gmail. comwrote:
I have implemented a static event. Is there anything special that i
have do? Is thread safety an issue?
Thread safety is as much an issue as it would be with an instance event.
The only difference is that with a static event you don't have the option
of dedicating an instance to each thread as a way of solving the thread
safety issues.
Otherwise, it's the same and you'd address the issues in the same way.
Pete

Thanks..

that means *static and instance event in singleton would make no
difference?

TIA
Yes but if you are attempting to write a singleton pattern I would
recommend sticking to static for the method you are going to invoke to
get the singleton instance. That is the safest way of getting it.
Apr 2 '08 #8
On Wed, 02 Apr 2008 10:58:50 -0700, Ben Voigt [C++ MVP]
<rb*@nospam.nos pamwrote:
No difference once the singleton is set up... creating the singleton only
once raises some new thread safety issues, especially if it is done
lazily.
Yes, of course. I'm ignoring the _new_ thread safety issues incurred
through the implementation of the singleton pattern. But yes, your
elaboration is an important consideration.

Pete
Apr 2 '08 #9
Hi Ben,

What do you mean by "creating the singleton only once raises some new thread
safety issues , especially if it is done lazily."?

1) If done properly, isn't a singleton object supposed to be created only
once anyway?

2) If the singleton is not done in a lazy way but instead you put a lock on
the whole operation, what other thread safety issues can arise?

Thanks


Apr 2 '08 #10

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

Similar topics

12
24813
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
8
12524
by: Colin Cashman | last post by:
In a program I'm writing, I have a class that generates a certain event. However, there may be dozens or even hundreds of instances of this particular class, which makes adding and removing handlers to each instance a pain. Rather than go down that route, I was thinking of making the event static, so I would only need to add my handlers once, to the static event, which I can then trigger from inside my class. That leaves me with two...
3
11832
by: Kirk Marple | last post by:
Just want to see if this is 'by design' or a bug... I have a common List<T> defined in a base class, and the base class has a static property to expose this list. I wanted the derived class to add items to this list, but have the base class hold the data and expose the property. Problem is, however, that the derived class' static constructor doesn't get called when DerivedClass.MyList is accessed, so the list has no members. If
2
2660
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the following type : Exception, Error, Warning, Infos (with differents colors, etc). I would like to use it like the Console.WriteLine("My Message"); on everywhere in my application.
0
1112
by: Dave L | last post by:
I just upgraded from VS .NET 2002 to 2003. Everything built okay, but strange bugs started appearing. Apparently there is a bug in the managed C++ compiler in regards to handling of static __events. In short, every new instance of the class clears all existing listening registered delegates. It should, of course, preserve all delegates since its static, but it does not according to this: "The real problem is the instance constructor...
5
1480
by: Superfox il Volpone | last post by:
I read in the glibc documentation that using 'static' in a function can save the content of a variable. So I want to use it to write a function that return the number of days in one month. Since the days on one month are even the some, it could be better to compute the array only one time. And so I did : int nDaysOnMonth(int month, int year){ static int i_dmonths; i_dmonths = i_dmonths = i_dmonths = i_dmonths = i_dmonths = i_dmonths =...
3
2310
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a static event declared in a C++ ref class, that can then be handled in a VB app. I'm trying to expose the static event through the interface that the C++ ref class implements so the VB app can use the interface as preferred. How do you expose a static event through an interface? In the example below as coded, in a VB app I can access and use the general method (MyMethod) if I declare my handle variable as an IMyInterface type....
1
1389
by: BLUE | last post by:
I know it's a stupid question but... I want to use a class that represents the current user of my application, another one that reads position from a GPS receiver and another one that reads RFID tags from a reader. I don't want to create a new user each time a log in appens (only one login at a time: mobile device) and I do not want to create a new object each time I read position or a tag, so it's right to use static classes and to update...
5
5903
by: BLUE | last post by:
I have a static class, so I've declared all variables static and also the event. This is the OnEvent method: { if (EventName != null) { // Invokes the delegates EventName(this, e); }
4
4531
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst child apps of an IIS application and can be used by multiple users during the application life cycle and for multiple page loads for the same or different page under a root application. What I don't understand and need to know is whether that...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10113
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.