OK I have a static class that has two static members, a string and a boolean.
A public static method assigns values to these members based upon the state of parameters passed in.
A private static method is then called that processes the static members.
The problem is that while the boolean keeps the value it is set to in the public function, the string does not; it defaults back to its initialised value. Why is this?
Simplified code is below.
static class MessageHandler
{
private static String m_messageToSend = String.Empty;
private static bool m_requiresACK = false;
public static void Send(String message)
{
//formatting etc (actual method sets more fields)
m_messageToSend = message;
m_requiresACK = true;
Send();
}
private void static Send()
{
SendMessageDelegate sendDelegate = DoSend;
//At this point m_requiresACK remains true but m_messageToSend does not
//hold value of message; it is empty.
IAsyncResult ar = sendDelegate.BeginInvoke(m_messageToSend, m_requiresACK);
//rest of function
}
}
//some other class
MessageHandler.Send("Hello");