如何在c#中使用多个gsm调制解调器 [英] how to use multiple gsm modem in c#

查看:84
本文介绍了如何在c#中使用多个gsm调制解调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究通过GSM调制解调器发送SMS的应用程序.由于一个调制解调器在一分钟内发送5条SMS,因此我预计发送1000条SMS将花费3个小时以上.这就是为什么我需要使用多个调制解调器以使调制解调器分担工作量的原因.假设我有4个调制解调器和一千条SMS要发送.我将为每个调制解调器分配250条SMS.我的问题是我无法让每个调制解调器同时发送其SMS.目前,我的c#等待一个调制解调器完成,然后转到另一个调制解调器,完全破坏了我对多个调制解调器的想法.关于如何启动多个独立进程的任何想法.就好像我在使用多个Exes一样?

I''m working on application that sends SMSs via GSM modem. Since one Modem sends like 5 SMSs in a minute, I anticipate that sending like a thousand SMSs will take more than 3 hours. That''s why I need to use multiple modems in such a way that the modems share the workload. Let''s say I have 4 modems and a thousand SMSs to send. I''ll allocate 250 SMSs to each modem. By my problem is I find no way of having each of the modems sending its SMSs concurrently. Currently, my c# waits until one modem finishes, then it goes to the other, completely defeating my idea of multiple modems. Any ideas how I can initiate several independent processes..As if I was using several Exes?

推荐答案

线程化.
查看 ^ ]-这可能是处理线程的最简单方法.每个调制解调器设置一个线程,并为每个线程分配单独的消息队列.



您好,谢谢您的答复,请给我更多详细信息,这是我连接串口的代码"


创建一个具有PortName字符串和List< T>的类. (或更好的Queue< t>)消息以在该端口上发送.
然后,如上面的链接中所示创建一个后台工作器对象,并使用类实例作为参数调用RunWorkerAsync.然后,您可以在DoWork事件中访问该实例,将e.Argument强制转换为您的类并访问这两个参数.
然后,它打开端口,并循环查看队列. (添加和删除项目时,可能需要使用lock).如果没有任何物品,请检查线程是否该死了,如果没有,请休眠一秒钟.
完成!
Threading.
Look at the BackgroundWorker class[^] - it is probably the simplest way of handling threads. Set up one thread per modem, and give each a separate queue of messages.



"hi orinial griff thank u very much for your reply please give me more detail here is my code to connect serial port"


Create a class which has a PortName string, and a List<T> (or better, a Queue<t>) of messages to send on that port.
Then create a background worker object as shown in the link above, and call RunWorkerAsync with the class instance as a parameter. You then access the instance in the DoWork event, cast e.Argument to your class and access the two parameters.
It then opens the port, and sits in a loop looking at the Queue. (You may need to use lock when adding and removing items). If there are no items, check if it is time for the thread to die, and sleep for one second if not.
Done!


这篇关于如何在c#中使用多个gsm调制解调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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