Answer the question
In order to leave comments, you need to log in
How to pass data to a running thread?
I have a thread that runs endlessly in a loop. But there was one problem. I can't pass periodically loaded data to a stream. Tried delegates. Useless.
public void Thread()
{
GetMessage msg = new GetMessage(Fail);
GetCommands val = new GetCommands(Check);
Ядро_хххх.BasicStructures.Command cmds = new Ядро_хххх.BasicStructures.Command();
do
{
#region Стадия записи.
if (cmd.Count > 0) cmds = cmd.ElementAt(0);
cmd.TryDequeue(out cmds); // в пределах класса копится, но здесь остаётся пустым
if (Device.CheckTxWaiting(ref numBytesWritten))
if (Commands.HasFlag(Ядро_хххх.BasicStructures.Command.NotOperation))
{
Device.Write(хххх.Upload(Outbox, Ядро_хххх.BasicStructures.Command.NotOperation), ref numBytesWritten);
IsButton = false;
RevisionTxFail = 0;
}
else
{
if (Commands.HasFlag(Ядро_хххх.BasicStructures.Command.LoadFPGAAll))
{
Device.Write(хххх.Upload(Outbox, Ядро_хххх.BasicStructures.Command.LoadFPGAAll), ref numBytesWritten);
//Commands = Ядро_хххх.BasicStructures.Command.NotOperation;
}
else
{
RevisionTxFail += 1;
if (RevisionTxFail > 1000) msg(5);
}
}
#endregion
#region Стадия чтения.
if (Device.CheckRxQueue(ref numBytesAvailable))
{
Device.Read(numBytesAvailable, ref ReadData, ref numBytesRead);
Inbox = хххх.Download(ReadData);
RevisionRxFail = 0;
}
else
{
RevisionRxFail += 1;
if (RevisionRxFail > 1000) msg(5);
}
#endregion
} while (IsWorking); // стоит всегда true, пока msg не изменит в значение false, в идеальном случае здесь всегда стоит true
//логика для работы с приёмом и передачей
}
Answer the question
In order to leave comments, you need to log in
And the field through which you shove data, is it volatile? Maybe this will help?
And what ConcurrentQueue did not please?
Enqueue(T) - added where data loaded
TryDequeue(T) - received in thread for processing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question