当前位置: 首页>>代码示例>>C#>>正文


C# Messenger.getMessage方法代码示例

本文整理汇总了C#中Messenger.getMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Messenger.getMessage方法的具体用法?C# Messenger.getMessage怎么用?C# Messenger.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Messenger的用法示例。


在下文中一共展示了Messenger.getMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        //Test method
        static void Main(string[] args)
        {
            Random random = new Random();
            Messenger messenger = new Messenger();

            double messageNum = 0;
            double inMessageNum = 0;
            int messageTest = 3;
            int delay = 10;
            if (args.Length == 1)
            {
                messageTest = Convert.ToInt32(args[0]);
            }
            else if (args.Length == 2)
            {
                messageTest = Convert.ToInt32(args[0]);
                delay = Convert.ToInt32(args[1]);
            }

            switch (messageTest)
            {
                // sends test messages
                case 1:
                    for (int i = 0; i <= 1000; i++)
                    {
                        messenger.sendMessage(i.ToString());
                        logger.Info("Sends message number: " + messageNum++);
                        Thread.Sleep(delay);
                    }
                    messenger.stopMessaging();
                    Thread.Sleep(delay);
                    break;
                // Receives messages until the finish command
                case 2:
                    while (!messenger.isMessagingFinished())
                    {
                        String inMessage = messenger.getMessage();

                        if (inMessage != null)
                        {
                            logger.Info("Gets message number: " + inMessageNum++);
                            Thread.Sleep(delay);

                        }
                    }
                    break;
                // Sends files in the dataset to the message listener
                case 3:
                    string[] filePaths = Directory.GetFiles(@"Dataset", "*");
                    foreach (string file in filePaths)
                    {
                        System.IO.StreamReader myFile =
                         new System.IO.StreamReader(file);
                        String message = myFile.ReadToEnd();
                        myFile.Close();
                        messenger.sendMessage(message);
                        logger.Info("Sends message number: " + messageNum++);
                        Thread.Sleep(delay);

                    }
                    messenger.stopMessaging();
                    Thread.Sleep(1000);
                    break;
                // Sends received messages
                case 4:
                    while (!messenger.isMessagingFinished())
                    {
                        String inMessage = messenger.getMessage();

                        if (inMessage != null)
                        {
                            logger.Info("Gets message number: " + inMessageNum++);
                            messenger.sendMessage(inMessage);
                            logger.Info("Sends message number: " + inMessageNum);
                            Thread.Sleep(delay);
                        }
                    }
                    break;
                // Sends files in the dataset to the message listener in a loop
                case 5:
                    while (true)
                    {
                        string[] filePaths2 = Directory.GetFiles(@"Dataset", "*");
                        foreach (string file in filePaths2)
                        {
                            System.IO.StreamReader myFile =
                             new System.IO.StreamReader(file);
                            String message = myFile.ReadToEnd();
                            myFile.Close();
                            messenger.sendMessage(message);
                            logger.Info("Sends message number: " + messageNum++);
                            Thread.Sleep(delay);

                        }
                    }
            }

            Console.WriteLine("Main program execeution finishes");
        }
开发者ID:project-first,项目名称:messaging,代码行数:100,代码来源:Test.cs


注:本文中的Messenger.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。