Discussion:
How to share data between Windows Service and .NET Remoting class?
(too old to reply)
Leo Violette
2009-04-03 21:57:06 UTC
Permalink
I have a C# Windows Service.

My Service class contains a ProcessJob object that I've implemented.
In OnStart of my Service Class, I construct the ProcessJob instance and tell
it to look for and start a job if it finds one.
In OnStop, I tell my ProcessJob instance to stop whatever it is doing.

I've now added .NET Remoting capability to the windows Service. I have a
new class in my Service project to implement my .NET Remoting methods.

I added a StopCurrentJob .NET remoting method. I'm wondering how to access
the ProcessJob from my .NET Remoting service.
I need a method that get's me the main application class and then cast it to
my service so that I can get to the ProcessJob instance it has created.

Any help?

Main Service class.
JobService.cs
namespace nsJobService
{
public partial class class JobService : ServiceBase
{
protected override void OnStart(string[] args)
{
m_jobProcess = new JobProcessor();
m_jobProcess.BeginJob();

// Code here was added to configure .NET Remoting.
}

protected override void OnStop()
{
m_jobProcess.StopJob();
}

private JobProcessor m_jobProcess;
public JobProcessor JobProcess
{
get { return m_jobProcess; }
}
}
}

Utility class for processing jobs.
JobProcessor.cs implements JobProcessor


.NET Remoting Implementation class
using namespace nsJobService
internal class ImplementJobProcess : MarshalByRefObject,
ISharedJobProcessInterface
{
void ISharedJobProcessInterface.CancelRunningJob()
{
// How to code this?
JobService jobService = (JobService)Application.GetServiceBase();
//??????
jobService.JobProcessor.StopJob();
}
}
Martin Dechev
2009-05-01 14:34:45 UTC
Permalink
Hi, Leo,

Can you make the JobProcessor a singleton? If you don't need any
initialization inside the OnStart of the service - you should be fine with
it being a singleton.

Martin Dechev
Post by Leo Violette
I have a C# Windows Service.
My Service class contains a ProcessJob object that I've implemented.
In OnStart of my Service Class, I construct the ProcessJob instance and
tell it to look for and start a job if it finds one.
In OnStop, I tell my ProcessJob instance to stop whatever it is doing.
I've now added .NET Remoting capability to the windows Service. I have a
new class in my Service project to implement my .NET Remoting methods.
I added a StopCurrentJob .NET remoting method. I'm wondering how to
access the ProcessJob from my .NET Remoting service.
I need a method that get's me the main application class and then cast it
to my service so that I can get to the ProcessJob instance it has created.
Any help?
Main Service class.
JobService.cs
namespace nsJobService
{
public partial class class JobService : ServiceBase
{
protected override void OnStart(string[] args)
{
m_jobProcess = new JobProcessor();
m_jobProcess.BeginJob();
// Code here was added to configure .NET Remoting.
}
protected override void OnStop()
{
m_jobProcess.StopJob();
}
private JobProcessor m_jobProcess;
public JobProcessor JobProcess
{
get { return m_jobProcess; }
}
}
}
Utility class for processing jobs.
JobProcessor.cs implements JobProcessor
.NET Remoting Implementation class
using namespace nsJobService
internal class ImplementJobProcess : MarshalByRefObject,
ISharedJobProcessInterface
{
void ISharedJobProcessInterface.CancelRunningJob()
{
// How to code this?
JobService jobService = (JobService)Application.GetServiceBase();
//??????
jobService.JobProcessor.StopJob();
}
}
Loading...