开发者

DataReceviedHandler Error, maybe thread Problem

In the DataReceviedHandler of an serial port i'm testing if a bool is set. If not I'm sending the next block to the serial port.

The boolean is set by the event of class. In the picture you can see that the programm goes into the if-statement, although the bool is false. Is this a thread problem? What could I do?

a busy cat http://img163.imageshack.us/img163/3324/boolh.png

If tried this:

                lock (_syncLock)
                {
                    if (_wr开发者_Go百科EEPROM)
                    {
                        //Hier müssen die weiteren 128er Blöche übertragen werden
                        SerialControl.Port.Write(_yTestMod.CreateYModemBlock(wrEE.EEPROMar, _eepromBlockIndex), 0,
                                                 _yTestMod.CreateYModemBlock(wrEE.EEPROMar, 2).Length);
                        _eepromBlockIndex += 1;
                    }
                }

and this in the event:

        lock (_syncLock)
        {
            _eeprom = false;
            _logger = false;
            _wrEEPROM = false;
        }

but it's still not working.


to the lock:

create a private field-variable:

private Object _syncLock = new Object();

and then where ever you set or read your "Flag"-variable use

lock(_syncLock)
{
  myFlag = true; // whatever
}

or

lock(_syncLock)
{
  return myFlag;
}

in your case wrap the hole handler for the event and your code shown above in such a lock to start with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜