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

C# events/threading

Hi,

I have a situation where I am capturing both a WMI event utilising the
"ManagementEventWatcher" in the "System.Management" namespace, and a
corresponding event ("EntryWritten") raised from the "EventLog" object in
the "System.Diagnostics" namespace.
When a certain event occurrs, both a WMI event is raised, and an event log
entry is written.
The problem I have is that I need to capture both events and somehow
correlate which WMI event relates to its associated "event log" event.
I need to retrieve data from the WMI object and also the event log to
populate a custom object.
I am having trouble understanding how the synchronisation of this should be
done. At the moment I have 2 class level variables - one is populated when
the WMI event is captured, and the other is populated when the event log
event is captured. I then check (in both onEvent methods) to see if they
are not null and then raise a custom event, then set the variables back to
null.

I am not too sure what better way to check for this, but I am pretty sure
that the way I am doing this is a big no no!

I hope I have explained this thoroughly enough - I am struggling to put the
problem into words!

Any help appreciated.

Bardo.
Nov 15 '05 #1
4 4066
Hi Bardo,

I am researching the issue, I will update you with new information ASAP.
Have a nice day.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Reply-To: "Bardo" <br**@nospam.bryn.com.au>
From: "Bardo" <br**@nospam.bryn.com.au>
Subject: C# events/threading
Date: Tue, 14 Oct 2003 16:07:37 +1000
Lines: 30
Organization: Bryn Systems
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <O2**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: 65-58.dsl.connexus.net.au 203.222.65.58
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191130
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Hi,

I have a situation where I am capturing both a WMI event utilising the
"ManagementEventWatcher" in the "System.Management" namespace, and a
corresponding event ("EntryWritten") raised from the "EventLog" object in
the "System.Diagnostics" namespace.
When a certain event occurrs, both a WMI event is raised, and an event log
entry is written.
The problem I have is that I need to capture both events and somehow
correlate which WMI event relates to its associated "event log" event.
I need to retrieve data from the WMI object and also the event log to
populate a custom object.
I am having trouble understanding how the synchronisation of this should be
done. At the moment I have 2 class level variables - one is populated when
the WMI event is captured, and the other is populated when the event log
event is captured. I then check (in both onEvent methods) to see if they
are not null and then raise a custom event, then set the variables back to
null.

I am not too sure what better way to check for this, but I am pretty sure
that the way I am doing this is a big no no!

I hope I have explained this thoroughly enough - I am struggling to put the
problem into words!

Any help appreciated.

Bardo.


Nov 15 '05 #2

Hi Bardo,

I think there may be one problem with your solution.
Soon after the WMI event is fired and WMI event variable is set, while the
eventlog variable has not been modified.
If at this time, another WMI event is fired and the WMI event variable is
set again for the latter event, then the latter WMI event will correlate
with the former eventlog event.

I think you should keep these 2 variables' access mutex, then the
association will be correct.

Beside this, I think your way of solution is suitable.
Do you find any other problem about your solution?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Bardo" <br**@nospam.bryn.com.au>
| From: "Bardo" <br**@nospam.bryn.com.au>
| Subject: C# events/threading
| Date: Tue, 14 Oct 2003 16:07:37 +1000
| Lines: 30
| Organization: Bryn Systems
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O2**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 65-58.dsl.connexus.net.au 203.222.65.58
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191130
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
|
| I have a situation where I am capturing both a WMI event utilising the
| "ManagementEventWatcher" in the "System.Management" namespace, and a
| corresponding event ("EntryWritten") raised from the "EventLog" object in
| the "System.Diagnostics" namespace.
| When a certain event occurrs, both a WMI event is raised, and an event log
| entry is written.
| The problem I have is that I need to capture both events and somehow
| correlate which WMI event relates to its associated "event log" event.
| I need to retrieve data from the WMI object and also the event log to
| populate a custom object.
| I am having trouble understanding how the synchronisation of this should
be
| done. At the moment I have 2 class level variables - one is populated
when
| the WMI event is captured, and the other is populated when the event log
| event is captured. I then check (in both onEvent methods) to see if they
| are not null and then raise a custom event, then set the variables back to
| null.
|
| I am not too sure what better way to check for this, but I am pretty sure
| that the way I am doing this is a big no no!
|
| I hope I have explained this thoroughly enough - I am struggling to put
the
| problem into words!
|
| Any help appreciated.
|
| Bardo.
|
|
|

Nov 15 '05 #3
Hi Jeffrey,

Thanks for the response.
Yes I thought that the solution I had would be a bit buggy in correlating
the events.
I am fairly new to threading issues, so is it possible for you to elaborate
when you say to keep the 2 variables access mutex?
Should the class level vars be static?
I have read the MSDN docco on the mutex class and I understand that it is
used for synchronising threads/processes, but I am still a bit unsure on how
to implement this.

I will try playing around with some samples now.

Cheers,

Bardo.

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:Lj*************@cpmsftngxa06.phx.gbl...

Hi Bardo,

I think there may be one problem with your solution.
Soon after the WMI event is fired and WMI event variable is set, while the
eventlog variable has not been modified.
If at this time, another WMI event is fired and the WMI event variable is
set again for the latter event, then the latter WMI event will correlate
with the former eventlog event.

I think you should keep these 2 variables' access mutex, then the
association will be correct.

Beside this, I think your way of solution is suitable.
Do you find any other problem about your solution?

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Bardo" <br**@nospam.bryn.com.au>
| From: "Bardo" <br**@nospam.bryn.com.au>
| Subject: C# events/threading
| Date: Tue, 14 Oct 2003 16:07:37 +1000
| Lines: 30
| Organization: Bryn Systems
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O2**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 65-58.dsl.connexus.net.au 203.222.65.58
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191130 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
|
| I have a situation where I am capturing both a WMI event utilising the
| "ManagementEventWatcher" in the "System.Management" namespace, and a
| corresponding event ("EntryWritten") raised from the "EventLog" object in | the "System.Diagnostics" namespace.
| When a certain event occurrs, both a WMI event is raised, and an event log | entry is written.
| The problem I have is that I need to capture both events and somehow
| correlate which WMI event relates to its associated "event log" event.
| I need to retrieve data from the WMI object and also the event log to
| populate a custom object.
| I am having trouble understanding how the synchronisation of this should
be
| done. At the moment I have 2 class level variables - one is populated
when
| the WMI event is captured, and the other is populated when the event log
| event is captured. I then check (in both onEvent methods) to see if they | are not null and then raise a custom event, then set the variables back to | null.
|
| I am not too sure what better way to check for this, but I am pretty sure | that the way I am doing this is a big no no!
|
| I hope I have explained this thoroughly enough - I am struggling to put
the
| problem into words!
|
| Any help appreciated.
|
| Bardo.
|
|
|

Nov 15 '05 #4

Hi Bardo,

If the two variable should be static lies on your program logic. The static
variable is assciated with the entire class, while the member variable is
associated with a certain instance.

I think if you use your two variables as non-static, then every time a WMI
event generates, you should create an instance of this class.
Because different instance did not share the same varables, the mutext is
no need.

If you use static variables, you need not create a new instance for every
event, but you should protect the share variables. This is what mutex take
effect.
You should protect your variables can not be access before it was clear to
null.
You can use .Net Mutex class to implement mutex access, I think it is easy
to use.

Because the mutex and sychronization is easy to generate error, I recommand
you create the variables as non-static.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Bardo" <br**@nospam.bryn.com.au>
| From: "Bardo" <br**@nospam.bryn.com.au>
| References: <O2**************@TK2MSFTNGP09.phx.gbl>
<Lj*************@cpmsftngxa06.phx.gbl>
| Subject: Re: C# events/threading
| Date: Thu, 16 Oct 2003 17:22:33 +1000
| Lines: 103
| Organization: Bryn Systems
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OL**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 65-58.dsl.connexus.net.au 203.222.65.58
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:191727
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Jeffrey,
|
| Thanks for the response.
| Yes I thought that the solution I had would be a bit buggy in correlating
| the events.
| I am fairly new to threading issues, so is it possible for you to
elaborate
| when you say to keep the 2 variables access mutex?
| Should the class level vars be static?
| I have read the MSDN docco on the mutex class and I understand that it is
| used for synchronising threads/processes, but I am still a bit unsure on
how
| to implement this.
|
| I will try playing around with some samples now.
|
| Cheers,
|
| Bardo.
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:Lj*************@cpmsftngxa06.phx.gbl...
| >
| > Hi Bardo,
| >
| > I think there may be one problem with your solution.
| > Soon after the WMI event is fired and WMI event variable is set, while
the
| > eventlog variable has not been modified.
| > If at this time, another WMI event is fired and the WMI event variable
is
| > set again for the latter event, then the latter WMI event will correlate
| > with the former eventlog event.
| >
| > I think you should keep these 2 variables' access mutex, then the
| > association will be correct.
| >
| > Beside this, I think your way of solution is suitable.
| > Do you find any other problem about your solution?
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | Reply-To: "Bardo" <br**@nospam.bryn.com.au>
| > | From: "Bardo" <br**@nospam.bryn.com.au>
| > | Subject: C# events/threading
| > | Date: Tue, 14 Oct 2003 16:07:37 +1000
| > | Lines: 30
| > | Organization: Bryn Systems
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <O2**************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 65-58.dsl.connexus.net.au 203.222.65.58
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:191130
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Hi,
| > |
| > | I have a situation where I am capturing both a WMI event utilising the
| > | "ManagementEventWatcher" in the "System.Management" namespace, and a
| > | corresponding event ("EntryWritten") raised from the "EventLog" object
| in
| > | the "System.Diagnostics" namespace.
| > | When a certain event occurrs, both a WMI event is raised, and an event
| log
| > | entry is written.
| > | The problem I have is that I need to capture both events and somehow
| > | correlate which WMI event relates to its associated "event log" event.
| > | I need to retrieve data from the WMI object and also the event log to
| > | populate a custom object.
| > | I am having trouble understanding how the synchronisation of this
should
| > be
| > | done. At the moment I have 2 class level variables - one is populated
| > when
| > | the WMI event is captured, and the other is populated when the event
log
| > | event is captured. I then check (in both onEvent methods) to see if
| they
| > | are not null and then raise a custom event, then set the variables
back
| to
| > | null.
| > |
| > | I am not too sure what better way to check for this, but I am pretty
| sure
| > | that the way I am doing this is a big no no!
| > |
| > | I hope I have explained this thoroughly enough - I am struggling to
put
| > the
| > | problem into words!
| > |
| > | Any help appreciated.
| > |
| > | Bardo.
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #5

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

Similar topics

10
by: Drakier Dominaeus | last post by:
This is my first time posting here, so please forgive me if I do anything incorrectly. I've been learning C# and working with different things and decided I wanted to get into Multi-Threading....
2
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app...
2
by: Philipp Sumi | last post by:
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 ();...
2
by: John Olbert | last post by:
Could someone recommend an indepth book(s) or set of articles on Events, Threading and Delegates under C#? We have run into a problem in which when an event was subscribed in code that the...
6
by: ankurw | last post by:
Hi All, I am experiencing a frustrating issue with hooking into COM events from a Windows service writting in C#. I create a COM object in the service and hook into an event exposed by the...
3
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
13
by: Bob | last post by:
My WinForms app runs on the single default thread, and uses a single SqlConnection object for all queries. I need to use one or more timers to periodically execute some of them. My own testing...
3
by: daan | last post by:
Hello, I have a problem and I can't get the solution for it :( I have a com dll, which i imported as a reference. The com object is part of a class which is multithreaded and will create...
3
by: Hardy Wang | last post by:
Hi all, I am migrating a Windows Form application from .Net 1.1 to 2.0. I try to use BackgroundWorker object to handle a very lengthy process. I have a separated class to handle some very complex...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...

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.