What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » [C#] EventLog and Threads

1 votes - 5 average   [C#] EventLog and Threads
Author: Message:
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
O.P. [C#] EventLog and Threads
Quick question: does anyone know how to write to the event log in a multi-threaded environment? MsgPlus just chucks the request away if it doesn't come from the main thread (which isn't very functionable reallly!)
10-21-2005 05:01 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] EventLog and Threads
It's a very interesting question.... Jedimark and I searched for the problem a while, and suddenly I remembered you can't write to the Event log from another Thread...

So the question should be (at least that's what I think): how to make another thread execute a function?
10-21-2005 06:58 PM
Profile E-Mail PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
O.P. RE: [C#] EventLog and Threads
Yeah, the problem is that MLP grabs song information from a Listener thread; I can't fundamentally change that... so I'm stuck with figuring out how to pass back a few string values to the main. But this goes beyond my programming knowledge...
10-21-2005 07:02 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: [C#] EventLog and Threads
An option might be to make an array, and everytime you want to add something to the event log you add it to the array (in the listener thread). In your main function there is a timer that checks the array every ... seconds (10 or so) and writes every line to the event log, and then clears the array...

It may be a strange option, but it might work. Although I'm sure there must be better options!
10-21-2005 07:08 PM
Profile E-Mail PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
O.P. RE: [C#] EventLog and Threads
Yeah I'd though of a similar function, I'll do a bit more thread research before I start messing round with stuff like that though.
10-21-2005 07:47 PM
Profile PM Find Quote Report
Jedimark
Full Member
***


Posts: 140
Reputation: 6
Joined: Apr 2002
O.P. RE: [C#] EventLog and Threads
The Solution:

Delegates!

I.e:
code:
private delegate void addEventLogDelegate(String thisContact, String thisTitle, String thisArtist);

And then in the other thread (one that isnt the main):
code:
addEventLogDelegate d = new addEventLogDelegate(this.addEventLog);
                        Object[] oArgs = new Object[3];
                        oArgs[0] = myUBX.getContact();
                        oArgs[1] = myUBX.getSong();
                        oArgs[2] = myUBX.getArtist();
                        this.Invoke(d, oArgs);
10-22-2005 10:07 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On