O
ohmmega
hello,
i've a method in the form_load event witch calls 2 beginread
statements (one after the other )
problem: during the second call it seem's that the callback won't be
triggered.
i've tried to wait for several seconds before calling the second call
- no effect.
but (!) if i put the method into a timer event it work's pretty fine.
help!!!
i'm also open for code improvement, if you just say WTF to the
following code:
<code>
public void sendMessage(string Message, string LineTerminator)
{
//WAIT FOR FREE CONNECTION
while (Locked)
{
System.Threading.Thread.Sleep(10);
//USED FROM OUTSIDE FOR SYNCHRONISATION
//WAIT STATE
Pending = true;
}
Locked = true;
Pending = false;
msStream = getStream(eCLIENTS.PARAMETER);
MessageStream msMessage = new MessageStream();
msMessage.LineTerminator = LineTerminator + "\r\n";
msMessage.bMessage = new Byte[1];
msMessage.sMessage = new StringBuilder();
msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack, msMessage);
msStream.Write(Encoding.ASCII.GetBytes(Message + "\r\n"),
0,Message.Length + 2);
}
private void OnMessageReceived(IAsyncResult asyncResult)
{
MessageStream msMessage = (MessageStream) asyncResult.AsyncState;
msMessage.sMessage.Append(Encoding.UTF7.GetString(msMessage.bMessage));
if ( (msMessage.sMessage.Length >= msMessage.LineTerminator.Length)
&&
(msMessage.sMessage.ToString().EndsWith(msMessage.LineTerminator)))
{
//extern event
MessageReady(msMessage.sMessage.ToString());
Locked = false;
ClientConnection(eCLIENTS.PARAMETER,false);
}
else
{
msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack,
msMessage);
}
}
i've a method in the form_load event witch calls 2 beginread
statements (one after the other )
problem: during the second call it seem's that the callback won't be
triggered.
i've tried to wait for several seconds before calling the second call
- no effect.
but (!) if i put the method into a timer event it work's pretty fine.
help!!!
i'm also open for code improvement, if you just say WTF to the
following code:
<code>
public void sendMessage(string Message, string LineTerminator)
{
//WAIT FOR FREE CONNECTION
while (Locked)
{
System.Threading.Thread.Sleep(10);
//USED FROM OUTSIDE FOR SYNCHRONISATION
//WAIT STATE
Pending = true;
}
Locked = true;
Pending = false;
msStream = getStream(eCLIENTS.PARAMETER);
MessageStream msMessage = new MessageStream();
msMessage.LineTerminator = LineTerminator + "\r\n";
msMessage.bMessage = new Byte[1];
msMessage.sMessage = new StringBuilder();
msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack, msMessage);
msStream.Write(Encoding.ASCII.GetBytes(Message + "\r\n"),
0,Message.Length + 2);
}
private void OnMessageReceived(IAsyncResult asyncResult)
{
MessageStream msMessage = (MessageStream) asyncResult.AsyncState;
msMessage.sMessage.Append(Encoding.UTF7.GetString(msMessage.bMessage));
if ( (msMessage.sMessage.Length >= msMessage.LineTerminator.Length)
&&
(msMessage.sMessage.ToString().EndsWith(msMessage.LineTerminator)))
{
//extern event
MessageReady(msMessage.sMessage.ToString());
Locked = false;
ClientConnection(eCLIENTS.PARAMETER,false);
}
else
{
msStream.BeginRead(msMessage.bMessage, 0, 1, delCallBack,
msMessage);
}
}