[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

HELP ASAP....Windows Service Errors....passing information from .cs file to another .cs file

Sorry to be such a novice about this but..... I have a windows service. It contains two separate files. Both have the same namespace name.

I need to pass "bDisplay" into the other file. I am getting several errors and not sure why or how to solve them does anyone have any help?

How do I access the other file?

ServerSocket.cs *This is where the main server start is so the" private bool m_bIsDisplayed = false;" had to go here so it didn't reset every time.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.IO;
using System.Net;      
using Listener;
using System.Threading;

namespace Listener
{
 private bool m_bIsDisplayed = false;

      public bool GetIsDisplayed()
      {
         return m_bIsDisplayed();
      }

      public void SetIsDisplayed(bool bDisplay)
      {
         m_bIsDisplayed = bDisplay;
      }

}

SocketListner.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Web;
using System.Windows.Forms;

using Listener;

namespace Listener
{

 private void MsgBxDisplayed(Byte [] byteBuffer, int size)
      {
         string sData = Encoding.ASCII.GetString(byteBuffer,0, size);  

         try
         {
            if (m_bIsDisplayed == true)
                 ///Need pass variable here of TRUE or FALSE so it doesn't continue with the default everytime.
            {
             
              System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);

            }
            else if (m_bIsDisplayed == false)
            {
               
               m_bIsDisplayed = true;
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);

               
           
               DialogResult result = MessageBox.Show("Failure", "WARNING!!", MessageBoxButtons.OK,
                               MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                               MessageBoxOptions.ServiceNotification);

               if(result == DialogResult.OK)
               {
                  // Closes the parent form.
                  //this.Close();
                  m_bIsDisplayed = false;
               }

            }

         }
         catch (Exception e)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
            "invalid IsDisplayed" + e.Message);
         }
         }

errors:

error CS0118: 'Listener.ServerSocket.m_bIsDisplayed' denotes a 'field' where a 'method' was expected
error CS0103: The name 'm_bIsDisplayed' does not exist in the class or namespace 'Listener.SocketListener'
error CS0103: The name 'm_bIsDisplayed' does not exist in the class or namespace 'Listener.SocketListener'
error CS0103: The name 'm_bIsDisplayed' does not exist in the class or namespace 'Listener.SocketListener'
error CS0103: The name 'm_bIsDisplayed' does not exist in the class or namespace 'Listener.SocketListener'
error CS0103: The name 'm_bIsDisplayed' does not exist in the class or namespace 'Listener.SocketListener'

0
NewMom2Brandon
Asked:
NewMom2Brandon
  • 6
  • 5
1 Solution
 
PaulCaswellCommented:
In your GetIsDisplayed method, try changing:

        return m_bIsDisplayed();

to

        return m_bIsDisplayed;

Paul
0
 
NewMom2BrandonAuthor Commented:
Thank you that takes care of one of my errors.
0
 
PaulCaswellCommented:
P.S.

Generally, if you have a 'Set' method and a 'Get' method for a property, you use it. I.E. In MsgBxDisplayed, you should not use m_bIsDisplayed, you should use Get/SetIsDisplayed(...).

Paul
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
NewMom2BrandonAuthor Commented:
I tried to run it in my MsgBxDisplayed but the problem is that this is a modal messagebox and if the user does not click the box closed it continually resets to false as if it where getting the request for the first time everytime...
So I have to place it into the first .cs file where the server is started (socketing)...so the IsDisplayed doesn't get reset to the default everytime.

So I need to pass it from one file (where the heart of the program is so to speaK) to the other.

0
 
PaulCaswellCommented:
>>Thank you that takes care of one of my errors.
Looking at it again, I'd guess that if you read and execute my P.S. that may remove your other errors too.

Paul
0
 
NewMom2BrandonAuthor Commented:
I tried it and it did get rid of the errors but does not give me the correct value.
0
 
PaulCaswellCommented:
Hmmm... I'd guess this is C# or something like it? I'm not familliar with the innards of C#. Perhaps you should get this question moved to the specific language topic rather than the general 'Programming' topic. Post a request with the mods and they'll move it.

Good luck. Remember me when the points are going down!! ;)

Paul
0
 
PaulCaswellCommented:
This is just a guess but it might be something about:

 private bool m_bIsDisplayed = false;

causing the flag to always be set to false on every invocation of the Get/Set methods. Is there a specific place where initialisors are place in this language? Is it C#?

Paul
0
 
NewMom2BrandonAuthor Commented:
I kept getting it to automatically default to false when it was in the file where the MsgBxDisplayed function is at. So I moved it into the main part which is a different file. I think this will make the application able to not reset automatically everytime the message comes in to me.

That is my thoery so I was putting it into the other file...to test my theory and I have to get the one file to be able to access it from the other file.

Oh boy I hope that makes sense
0
 
PaulCaswellCommented:
Makes sense!!! Good thinking!!! I am a 'C' and 'C++'(slightly) programmer. Correct me if I'm wrong but this int 'C++' is it?? So, sadly, I cant advise you on the initialisation/creator/destructor mechanisms here.

Paul
0
 
NewMom2BrandonAuthor Commented:
Nope it is C#

I will remember you for points though!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now