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

T

Tressa

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'
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You cannot declate variables at the namespace level. Either use a public
static class member/property (I'd say it's a bad programming style), or pass
the value of the flag as an argument in a method call.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Tressa said:
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'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top