Click here to Skip to main content
16,010,427 members
Home / Discussions / C#
   

C#

 
QuestionHow to know the fact that desktop in changed? Pin
dhami_naresh22-Aug-07 7:37
dhami_naresh22-Aug-07 7:37 
AnswerRe: How to know the fact that desktop in changed? Pin
snorkie22-Aug-07 11:53
professionalsnorkie22-Aug-07 11:53 
GeneralRe: How to know the fact that desktop in changed? Pin
dhami_naresh22-Aug-07 16:12
dhami_naresh22-Aug-07 16:12 
AnswerRe: How to know the fact that desktop in changed? Pin
Luc Pattyn22-Aug-07 13:10
sitebuilderLuc Pattyn22-Aug-07 13:10 
GeneralRe: How to know the fact that desktop in changed? Pin
dhami_naresh6-Sep-07 19:56
dhami_naresh6-Sep-07 19:56 
QuestionWindows service + COM STA Pin
SteveL1223422-Aug-07 7:29
SteveL1223422-Aug-07 7:29 
AnswerRe: Windows service + COM STA Pin
kubben22-Aug-07 8:29
kubben22-Aug-07 8:29 
AnswerRe: Windows service + COM STA Pin
SteveL1223423-Aug-07 5:01
SteveL1223423-Aug-07 5:01 
With some help from a coworker, I figured out how to do this.

The message loop can be run on the same thread as the COM object using ApplicationContext and Application.Run. Other objects can communicate to the thread via Invoke on a dummy Control created on the message loop thread.

<code>
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace TestMessageLoopWindowsService
{
internal class TestMessageLoop
{
internal void Start(EventLog eventLog)
{
if (eventLog == null)
throw new ArgumentNullException("eventLog");
this.eventLog = eventLog;

Thread messageLoopThread = new Thread(MessageLoopThread);
messageLoopThread.Name = "Message Loop Thread";
messageLoopThread.SetApartmentState(ApartmentState.STA);
messageLoopThread.Start();

Thread invokeOnToMessageLoopThread = new Thread(Invoker);
invokeOnToMessageLoopThread.Name = "Invoker";
invokeOnToMessageLoopThread.IsBackground = false;
invokeOnToMessageLoopThread.Start();
}
private EventLog eventLog;

private void MessageLoopThread()
{
ApplicationContext context = new ApplicationContext();

control = new Control();
control.HandleCreated += new EventHandler(control_HandleCreated);
control.CreateControl();

Application.Run(context);
}
private Control control;

private void control_HandleCreated(object sender, EventArgs e)
{
okToInvoke = true;
}
private volatile bool okToInvoke;

private void Invoker()
{
while (true)
{
if (okToInvoke)
{
EventHandler method = new EventHandler(InvokedOnMessageLoop);
control.Invoke(method);
}
Thread.Sleep(1000);
}
}

private void InvokedOnMessageLoop(object sender, EventArgs e)
{
eventLog.WriteEntry("InvokedOnMessageLoop runs on " + Thread.CurrentThread.Name);
}
}
}
</code>
QuestionStringBuilder Pin
elwoofy22-Aug-07 6:47
elwoofy22-Aug-07 6:47 
AnswerRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 7:00
mentorGiorgi Dalakishvili22-Aug-07 7:00 
AnswerRe: StringBuilder Pin
Scott Dorman22-Aug-07 7:23
professionalScott Dorman22-Aug-07 7:23 
GeneralRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 7:41
mentorGiorgi Dalakishvili22-Aug-07 7:41 
GeneralRe: StringBuilder Pin
Scott Dorman22-Aug-07 8:01
professionalScott Dorman22-Aug-07 8:01 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 8:05
mvePIEBALDconsult22-Aug-07 8:05 
GeneralRe: StringBuilder Pin
Scott Dorman22-Aug-07 8:13
professionalScott Dorman22-Aug-07 8:13 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 9:08
mvePIEBALDconsult22-Aug-07 9:08 
GeneralRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 9:23
mentorGiorgi Dalakishvili22-Aug-07 9:23 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 10:00
mvePIEBALDconsult22-Aug-07 10:00 
GeneralRe: StringBuilder Pin
Luc Pattyn22-Aug-07 13:21
sitebuilderLuc Pattyn22-Aug-07 13:21 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 14:43
mvePIEBALDconsult22-Aug-07 14:43 
GeneralRe: StringBuilder Pin
Luc Pattyn22-Aug-07 14:55
sitebuilderLuc Pattyn22-Aug-07 14:55 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 17:57
mvePIEBALDconsult22-Aug-07 17:57 
QuestionRecording movement on a GUI of an application Pin
thedavejay22-Aug-07 6:27
thedavejay22-Aug-07 6:27 
AnswerRe: Recording movement on a GUI of an application Pin
Ravi Bhavnani22-Aug-07 10:46
professionalRavi Bhavnani22-Aug-07 10:46 
GeneralRe: Recording movement on a GUI of an application Pin
thedavejay23-Aug-07 6:32
thedavejay23-Aug-07 6:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.