同时入队和出队? [英] Enqueue And Dequeue In Same Time?

查看:178
本文介绍了同时入队和出队?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧



我想同时为队列添加值,而不需要休息一下就可以将队列中的值读入队列中。



我希望每次用户输入我存储在队列中的每个字符以及用户按下Enter键时,存储在变量中的值都会存储它。换句话说,它将删除队列中的值。但与此同时,用户可能会重新输入值,但由于程序侧重于Dequeue,因此无法正常运行。



我该怎么办? br $>


Hi everyone

I want to add value to the queue at the same time without taking a break to read the value from the queue into the queue exist.

I want that every time the user enters each character that I had stored in a queue and when the user pressed Enter Key , values ​​stored in a variable to store it. In other words, it would delete the value from the queue. But at the same time, the user may re-enter the value, but because the program focuses on Dequeue ,does not run properly.

What must I do?

private void TimeOfRead_Tick(object sender, EventArgs e)
{
  if(Keys.Enter)
  {
     myStr += Value;
     ****PrimaryQueueu.Enqueue(Str);
     Str = "";
  }
}            

private void timerSendMail_Tick(object sender, EventArgs e)
        {
            if(PrimaryQueueu.Count > 0)
            {
                ****MyMessage.Body = PrimaryQueueu.Dequeue().ToString();
                try
                {
                    SmtpClient.Send(MyMessage);
                }
                catch
                {

                }
            }
        }

推荐答案

对你的'TimeOfRead_Tick'感到困惑



我认为它应该是KeyUp



1.在KeyUp上,如果输入则按下按键,如果没有,则将其添加到某个静态字符串中

2.如果输入onkeyup你排队那个字符串并清除静态

3.你的扫描计时器在timerSendMail_Tick上发射将出列,我想如果你的catch块被执行则再次入队



想知道你为什么要使用计时器来检测输入以及为什么会有你的按键,如果没有答案你能解决一下这个问题吗?
confused about your 'TimeOfRead_Tick'

to my mind it should be KeyUp

1. On KeyUp you taste on the keypressed if it is enter and if not add it to some static string
2. if it is enter onkeyup you enqueue that string and clear the static
3. your scan timer fireing on timerSendMail_Tick will dequeue and i think enqueue it again if your catch block is ever executed

wonder why you're using a timer to detect enter and why that would have your keypress, could you clear the question up a bit if that doesn't answer?

这篇关于同时入队和出队?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆