如何维护一个始终在c#.net中监控的队列? [英] How to maintain a Queue which is always monitoring in c#.net?

查看:85
本文介绍了如何维护一个始终在c#.net中监控的队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友我需要帮助编码..



实际上我正在开发通过软电话拨打电话的应用程序。



在这个我有四个端口意味着我可以打四个电话。



这里我将从webservices获取我需要的联系号码放入队列然后必须检查4端口任何至少一个端口是免费的..如果空闲,那么一个联系号码必须从队列中挑选并再次进行dail,继续检查是否有四个端口任何一个端口免费然后从队列中传递另一个号码。





像这个队列必须始终注意端口是免费的还是没有...如果免费则通过队列中的号码。



这里呼叫自动结束后我正在改变端口可用性,否则端口很忙,就像这个状态将继续改变..根据队列的状态必须通过数字....



仍然不清楚na皱眉| :( .......



试着尽可能多地解释一下......



示例代码:

Hi Friends I need help in coding..

Actually I am developing application for making call by soft phones.

In this i have fours ports means at a time i can make four calls.

Here I will get contacts number from webservices those numbers i need to put in Queue then have to check that 4 ports any atleast one port is free or not.. If free then one contact number have to pick from queue and make to dail again that keep on checking that amoung four ports any one port free then pass another number from queue.


Like this queue must be always watching that ports are free or not... if free then pass number from queue.

"Here after call ended automatically am changing port availability otherwise ports are busy like this status wil be keep on changing.. According to the status that queue must pass numbers....

Still not clear na Frown | :( .......

Trying to explain as much as possible you guys....

Sample code:

// code in Form load
ThreadStart ts = new ThreadStart(severgetdata);
Thread serverthread = new Thread(ts);
Thread CurrentThread = serverthread;
serverthread.Start();

// Above lines starting thread.

// servergetdata()

// In this method am getting numbers which i have to dailed... Here for example am using socket layer. By telnet am sending contact number which i have to dailed

public void severgetdata()
{
   byte[] bytes = new Byte[1048576];

   // Establish the local endpoint for the socket.
   // Dns.GetHostName returns the name of the 
   // host running the application.
   IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
   IPAddress ipAddress = ipHostInfo.AddressList[0];
   IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

   // Create a TCP/IP socket.
   Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);

   // Bind the socket to the local endpoint and 
   // listen for incoming connections.
   try
   {
      listener.Bind(localEndPoint);
      listener.Listen(10);

      // Start listening for connections.
      while (true)
      {
         Console.WriteLine("Waiting for a connection...");
         // Program is suspended while waiting for an incoming connection.
         Socket handler = listener.Accept();
         data = null;

         // An incoming connection needs to be processed.
         while (true)
         {
            int bytesRec = handler.Receive(bytes);
            data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
            if (data.IndexOf("") > -1)
            {
               break;
            }
         }

         // Show the data on the console.
         Console.WriteLine("Text received : {0}", data);

         // Echo the data back to the client.
         byte[] msg = Encoding.ASCII.GetBytes(data);
         handler.Send(msg);
         string receivedata = data;

         receivedata = receivedata.Remove(receivedata);

         //After getting contact numbers then am trying to put in Queue.
         QueueCustomers(receivedata);

         Checkports();
         MakeCall();

         handler.Shutdown(SocketShutdown.Both);
         handler.Close();
      }
   }

   catch (Exception e)
   {
      Console.WriteLine(e.ToString());
   }

   Console.WriteLine("\nPress ENTER to continue...");
   Console.Read();
}

// Here I am sending the numbers to Queue like this. after adding in queue then have to check the ports are free or not in CheckPorts() method

public void QueueCustomers(string receivedata)
{
   callCustomer.contactnumber = receivedata;
   CustomerQueue.Enqueue(callCustomer);
   int count = CustomerQueue.Count;
}


Public void Checkports()
{

   // Here am checking ports free or not.
   // if ports available then go for makecall otherwise wait until port get free.

   //ports status will be 1) free---> at initial stage
   // 2) available--> after getting free stage port then change it to available
   // 3) busy----> once call is connected

   // After call ended then states of port wil be changed to free.

   // So whenever the port is free then one number must be come from that queue.....

}



我在这里添加了示例代码,请仔细阅读。我正计划这样处理。像这样,队列必须在端口状态下工作..我不知道如何让队列继续检查端口状态.....



谢谢&问候

S Chand Basha


I added sample code here please go through it. I am planning like this to handle. Like this the queue must work on ports states.. I dont know how to make a queue continues to check the ports status.....

Thanks & Regards
S Chand Basha

推荐答案

当我看到你的挑战时,我建议你选择三个选项中的一个。

1. Oldschool MSMQ将在机器重新启动后继续使用队列中的元素并且绝对是最安全的方式并且它已存在多年: http://msdn.microsoft.com/en-us/library/ms978430.aspx [ ^ ]

2.制作一个Web API控制器,它也可以对任何提交进行操作,就像你希望的那样< a href =http://www.codeproject.com/Articles/549152/Introduction-to-ASP-NET-Web-API> ASP.NET Web API简介 [ ^ ]

3.做一个完整的WCF服务 http://msdn.microsoft.com/en-us/library/ms731082(v = vs.110).aspx [ ^ ]
As i see your challenge i would suggestion you to choose one of three options.
1. Oldschool MSMQ will survive across machine reboots with elements in queue and is definitively the safest way and it has existed for ages: http://msdn.microsoft.com/en-us/library/ms978430.aspx[^]
2. Make a Web API controller, which will act on any submission also, like you wished Introduction to ASP.NET Web API[^]
3. Do a full blown WCF service http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx[^]


这篇关于如何维护一个始终在c#.net中监控的队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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