[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Service and class pass data?

Posted on 2006-07-03
7
Medium Priority
?
200 Views
Last Modified: 2010-05-18
I have a nicely running service.

Now I need to include a restriction for licensing sake.

The service must 'call' a method in a seperate class to continune running.

The problem is that the service keeps running regardless.

So, it appears the class data is not successfully passed to the service.

Here's the code:

[service1.cs]

protected override void OnStart(string[] args)
{
    Class1 class1 = new Class1();
    bool ok = class1.Check();
   if (ok)
   {
     run = true;
   }
   else
  {
     run = false;
  }
}


[Class1.cs]

public bool Check()
        {          
            bool result;
           
            if (info1 != info2)
            {
                result = false;
            }
            else
            {              
                result = true;
            }
            return result;            
        }    

0
Comment
Question by:kvnsdr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17030799
I don't see where run = true/false does anything.

Bob
0
 
LVL 21

Expert Comment

by:mastoo
ID: 17030929
You need to instantiate a servicecontroller for your service, and then use it to stop your service.
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 17031095
Sorry, maybe I was too breif with my code example.

I learned the "Whie(Run)" on another web site that effectively stops code execution.

So, if I can get the correct bool info from Class1.cs to either allow or disallow the service to run..


bool Run = true;

 protected override void OnStart(string[] args)
 {
      Thread thread = new Thread(new ThreadStart(StartCode));
      thread.Start();
}

 public void StartCode()
{          
     while (Run)
     {
          // code runs here
     }
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:gbzhhu
ID: 17031225
Your assumption ios based on those 2 variables being equal or not

 if (info1 != info2)

Were are the values coming from?

I think the question is slightly on the vague side
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 17031333
The values of (info1 != info2) represent the results of a very long matmatical equation.

I DO know the result is == and my return bool = true.

I simply would like to know how to pass the bool value from the Class1.cs to the Service1.cs...


0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 17031357
Are you saying that you know the class method Check returns true BUT the line
bool ok = class1.Check();
is not assigning the ok variable a true value?

If check method returns true then passing that value back to the service is exactly what you are doing, I can't see anything wrong with it
0
 
LVL 12

Accepted Solution

by:
gbzhhu earned 750 total points
ID: 17031396
Then only thing questionable that i can see is that you are using a new thread.  I am not sure setting the Run = somevalue in the main thread and accessing it on the new spawned thread is thread safe.  have you tried without the threading?

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question