473,396 Members | 1,877 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,396 software developers and data experts.

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 2937
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...@nnowslpianmk.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...@nnowslpianmk.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.nospamwrote:
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
Rene wrote:
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?
Doing that in a threaded application is pretty challenging. If you use a
type initializer, .NET will do the synchronization for you, which is
typically the way to go. .NET may, but is not required to, run type
initializers lazily.
>
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 #11

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

Similar topics

12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
8
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...
3
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...
2
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...
0
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...
5
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...
3
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...
1
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...
5
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
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.